Generating an ascending list of numbers of arbitrary length in python
range(10)
is built in.
If you want an iterator that gives you a series of indeterminate length, there is itertools.count()
. Here I am iterating with range()
so there is a limit to the loop.
>>> import itertools
>>> for x, y in zip(range(10), itertools.count()):
... print x, y
...
0 0
1 1
2 2
3 3
4 4
5 5
6 6
7 7
8 8
9 9
Later: also, range() returns an iterator, not a list, in python 3.x. in that case, you want list(range(10))
.
You want range()
.