You can replace loop with with `return range(1, self.segment_max + 1)`. But also import `range` from `compat` to get the iterator version of range on Python 2.