Skip to content

Instantly share code, notes, and snippets.

@crackwitz
Created October 18, 2015 22:27
Show Gist options
  • Select an option

  • Save crackwitz/c32e863a16dcb7672c97 to your computer and use it in GitHub Desktop.

Select an option

Save crackwitz/c32e863a16dcb7672c97 to your computer and use it in GitHub Desktop.
import itertools
def cartesian(*lists):
if len(lists) == 0:
yield ()
else:
for t in cartesian(*lists[1:]):
for x in lists[0]:
yield (x,) + t
input = [ [0,1,5,6], [0,10], [7,8,9] ]
output = itertools.imap(sum, cartesian(*input)) # generator
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment