Re: is there a shorter way to write this

2009-01-29 Thread Tim Chase
Hmm, sounds like homework, but I'll bite. The underlying problem does sound like homework, but the OP posted a working solution, and was only looking for ways to improve it. So I'm a little more lenient on providing alternatives. It's true that the homework problem may have been exactly as

RE: is there a shorter way to write this

2009-01-29 Thread Andreas Tawn
> 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

Re: is there a shorter way to write this

2009-01-29 Thread Tim Chase
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(

Re: is there a shorter way to write this

2009-01-29 Thread Stephen Hansen
If the list is unique of 26 elements is guaranteed to be unique, simply: > Wow, 6am copy editing of my own posts is terribly ineffective. "If the list of 26 elements is guaranteed to be unique" -- http://mail.python.org/mailman/listinfo/python-list

Re: is there a shorter way to write this

2009-01-29 Thread Vlastimil Brom
2009/1/29 garywood : > 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(li

Re: is there a shorter way to write this

2009-01-29 Thread Stephen Hansen
On Thu, Jan 29, 2009 at 6:11 AM, garywood wrote: > I had a task in a book to pick 5 items from a list of 26 ensuring the > items are not repeated > > If the list is unique of 26 elements is guaranteed to be unique, simply: >>> import random >>> random.sample(list, 5) ['g', 'y', 'i',

is there a shorter way to write this

2009-01-29 Thread garywood
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