I have implemented this algorithm:
def get_hot_pages(self, radius = 2):
if self.page == None or self.max_pages == None: return []
hot_pages = []
for page in xrange(self.page - radius, self.page + radius + 1):
if page < 0 or page >= self.max_pages : continue
hot_pages.append(page)
return hot_pages
But something tells me this can be implemented better. Is there a more pythonic way to do this?
The usual “trick” is to use
max()andmin()in order to set the minimum and maximum page numbers:The main advantages of this approach are: