Q:

Python: function returning numbers in ascending order

How can I write a function that would give me a new number in ascending order every time i call it?
For example, if I call it for the first time it returns "1", if I call again, it returns "2". 

A:

How about itertools.count()?
counter = itertools.count()
print next(counter)
print next(counter)
print next(counter)

prints
0
1
2

If you want your counter to start from 1, use
counter = itertools.count(1)

