[Tutor] cycle w/ shuffle
Kent Johnson
kent37 at tds.net
Thu Apr 27 03:17:40 CEST 2006
kevin parks wrote:
> it seems to me that i need something like itertools cycle, except that
> i need to keep track of when i have exhausted my list and then call
> random.shuffle() on my sequence.
>
> def cycle(iterable):
> saved = []
> for element in iterable:
> yield element
> saved.append(element)
> while saved:
random.shuffle(saved) ###############
> for element in saved:
> yield element
Kent
More information about the Tutor
mailing list