List Info

Thread: cycle w/ shuffle




cycle w/ shuffle
user name
2006-04-29 22:51:51
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-requestpython.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

_______________________________________________
Tutor maillist  -  Tutorpython.org
http://
mail.python.org/mailman/listinfo/tutor
[1]

about | contact  Other archives ( Real Estate discussion Medical topics )