Created
October 18, 2015 22:27
-
-
Save crackwitz/c32e863a16dcb7672c97 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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