[Tutor] cycle w/ shuffle
kevin parks
kp8 at mac.com
Sun Apr 30 00:51:51 CEST 2006
Thanks Kent. That is what i did the first time around but it didn't
work ...
but that was do to something else that was not working in the script....
hehe.... of course, this just shuffles the saved copy of the list which
is
egg-zactly what i needed "duh" ... sorry... gosh... <red face=on>
-kevin--
On Apr 27, 2006, at 6:00 AM, tutor-request at python.org wrote:
> 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