Dave, Myles, et al, On Nov 27, 2011, at 4:25 PM, Dave Angel <d...@davea.name> wrote:
> On 11/27/2011 05:17 PM, myles broomes wrote: >> >> >> >> >> >> >> >> #random order list >> while len(random_word_list) != len(word_list): >> word = random.choice(word_list) >> if word not in random_word_list: >> random_word_list += word >> > If you use += operator with list on the left side, it assumes something > compatible with list on the right. So either use > random_word_list += [word] > Or else use random_word_list.append(word) >> >> >> >> >> Everyone has offered some good feedback, I just wanted to throw in this, and hopefully everyone can say if I'm correct or not: 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)) This will prevent infinite loops, easier to read, and allows for a lot of other uses (even if x is never used). Any thoughts people? And would this method (on a small or large scale) be 'cheaper' than the original conditional? Or more 'pythonic'? Charles Sent from my iPhone
_______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor