[Tutor] weighted choices from among many lists

kevin parks kp8 at mac.com
Sun Mar 12 04:18:36 CET 2006

> 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 :-)
> Try
>    lst_name, lst = windex(x)
> then random.choice() and print.

Thanks Kent i got it, just another brain-fart on my side...

I was already doing something like:

lst_name, lst = windex(x)
pick = random.choice(lst)

But instead of:
print i, lst_name, pick

I was idiotically still printing:
print i, lst, pick

now matter how you unpack it all... you are still gonna get lst if that 
is what
is in your print statement... grrr....

of course the another way i would be a use a dictionary and us the list 
name as
a key... the list as a value...



More information about the Tutor mailing list