Reputation: 78683
I'm looking for a standard function that does this:
def Forever(v):
while True:
yield v
It seems so trivial I can't believe there isn't a standard version.
For that matter anyone know of a good link to a list of all the standard generator functions?
Upvotes: 5
Views: 1600
Reputation: 527338
itertools.repeat(x[, count])
repeats x a finite number of times if told how many times, otherwise repeats forever.
For a general list of all of the itertools generator functions, see here:
http://docs.python.org/library/itertools.html
Upvotes: 16
Reputation: 817030
Your are looking for itertools.repeat(object[, times])
:
Make an iterator that returns
object
over and over again. Runs indefinitely unless thetimes
argument is specified.
Upvotes: 10