I want to loop through a list and check all the possible combinations in it. Currently, I'm using a series of nested for loops, and obviously I'm not ecstatic with the speed using this method. It's very slow and can take 20-30 minutes to go through all the combinations.
for n1 in list1:
list.append(n1)
for n2 in list2:
list.append(n2)
for n3 in list2:
list.append(n3)
for n4 in list3:
list.append(n4)
for n5 in list3:
list.append(n5)
for n6 in list4:
list.append(n6)
for n7 in list4:
list.append(n7)
for n8 in list5:
list.append(n8)
for n9 in list5:
list.append(n9)
some logic that determines a value
list.remove(n9)
list.remove(n8)
list.remove(n7)
list.remove(n6)
list.remove(n5)
list.remove(n4)
list.remove(n3)
list.remove(n2)
list.remove(n1)
I have no illusions that this is a good way of doing this. I just can't think of a better way of handling this. There ends up being a TON of combos, but I need to calculate the value of each one. There are 5 lists, the combinations I need to check consist of one from list 1, and two spots from list 2-5.
If anyone has suggestions on how to improve this or anyway in python to imrpove the speed of this, that would be appreciated.
The final combination looks something like this:
List1[n1], list2[n2], list2[n3], list3[n4], list3[n5], list4[n6], list4[n7], list5[n8], list5[n9].
Also, there are combinations where list2 for example could be list2[0],list2[1]
and list2[1], list2[0]
which for my purposes are the same thing. Eliminating duplicates like that could reduce my combinations, but I'm unsure of how to approach that.