Calling a generator multiple times
Terry Reedy
tjreedy at home.com
Thu Dec 6 15:39:06 EST 2001
"Bruce Eckel" <Bruce at EckelObjects.com> wrote in message
news:mailman.1007665994.20287.python-list at python.org...
> I'm trying to create a clever way to call a generator multiple
> times, but the only thing I've been able to come up with is:
>
> import random
> rgen = random.Random()
> def itemGenerator(dummy):
> return rgen.choice(['one', 'two', 'three', 'four'])
>
> print map(itemGenerator, [None]* 25)
>
> This works, but it requires the 'dummy' argument which seems
> inelegant. I'll bet someone has a better idea...
Use for i in range(25):
Terry J. Reedy
More information about the Python-list
mailing list