is there a shorter way to write this

garywood pythonsky at sky.com
Thu Jan 29 15:11:30 CET 2009


I had a task in a book to pick 5 items from a list of 26 ensuring the items are not repeated


import random
list = ['a','b','c','d','e','f','g','h','i','j','k','l','m',
        'n','o','p','q','r','s','t','u','v','w','x','y','z']
word = ' '
a = random.choice(list)
list.remove(a)
b = random.choice(list)
list.remove(b)
c = random.choice(list)
list.remove(c)
d = random.choice(list)
list.remove(d)
e = random.choice(list)
list.remove(e)
word = a + b + c + d + e
print (word)
print(list)

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20090129/71b504cf/attachment.html>


More information about the Python-list mailing list