Calling a generator multiple times

Bruce Eckel Bruce at
Thu Dec 6 20:13:29 CET 2001

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...

Most current information can be found at:
Bruce Eckel
Contains free electronic books: "Thinking in Java 2e" & "Thinking
in C++ 2e"
Please subscribe to my free newsletter -- just send any email to:
join-eckel-oo-programming at
My schedule can be found at:

More information about the Python-list mailing list