Feed on
Posts
Comments

let’s say you’ve got a list of the numbers 0 through 4 and you wanted all 32 possible combinations of them.  to get that list:

list_of_five = range(0,5)   

swap_list_list = [[]]

for swap in list_of_five:

    temp_lists = []

    for list_stub in swap_list_list:

        this_list = copy.copy(list_stub)

        this_list.append(swap)

        temp_lists.append(this_list)

temp_lists.append(list_stub)

    swap_list_list = temp_lists

print swap_list_list

 

 

Stumble it!

if that was helpful ...

check out the other tips and tricks i've compiled on these pages. you might learn something else interesting!

Did I get this wrong? Let me know!

Trackback URI | Comments RSS

More blogs about http://desk.stinkpot.org:8080/tricks.