I have N Lists I\'d like to find unique combinations of. I\'ve written it out on my whiteboard and it all seems to have a pattern, I just haven\'t found it
I'm assuming that you want the Cartesian product - all possible lists created by choosing exactly one element from each list. You can implement it recursively, like this:
def cartesian_product(l):
if l:
for b in cartesian_product(l[1:]):
for a in l[0]:
yield [a] + b
else:
yield []
l = [
[ 'a', 'b' ],
[ 'c', 'd', 'e' ],
[ 'f', 'g' ],
]
for x in cartesian_product(l):
print x
Update: ~unutbu's suggestion of itertools.product is better, but I'll leave this here anyway.