[Tutor] weighted choices from among many lists

Kent Johnson kent37 at tds.net
Sun Mar 12 03:37:52 CET 2006

kevin parks wrote:
>>From: Kent Johnson <kent37 at tds.net>
>>If you want to be able to print the name of the list then you could
>>include both the name and the actual list in x:
>>	x = [(('lst_a', lst_a), .50), etc...]
> That produces:
> ('lst_c', ['Ale', 'Lager', 'Pilsner', 'Bock', 'Porter', 'Stout'])
> ['Ale', 'Lager', 'Pilsner', 'Bock', 'Porter', 'Stout']
> i am actually trying to get name of list, the choice like so:
> lst_c
> Bock

Yes, you need to unpack the result of calling windex(). You so ably 
demonstrated unpacking the list in your for loop I thought you would 
figure it out :-)

   lst_name, lst = windex(x)

then random.choice() and print.


More information about the Tutor mailing list