[Tutor] Random order program

Alan Gauld alan.gauld at btinternet.com
Mon Nov 28 09:45:54 CET 2011


On 28/11/11 07:57, Charles Becker wrote:
> A way to make the code more 'pythonic' and easier to read might be to
> replace the conditional
> 	while len(random_word_list) != len(word_list)
> With the following :
> 	for x in range(len(word_list))

Unfortunately that won't work with the OPs algorithm.
It involves randomly extracting an item from word_list until all items 
have been chosen, this is likely to require many more iterations than 
the number of items in the list because the random choice will pick some 
items more than once.

This is why we are suggesting that a different algorithm be used instead!

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/



More information about the Tutor mailing list