Pythonic way to iterate through a range starting at 1

range(1, n+1) is not considered duplication, but I can see that this might become a hassle if you were going to change 1 to another number.

This removes the duplication using a generator:

for _ in (number+1 for number in range(5)):
    print(_)

Leave a Comment