Skip to content

Instantly share code, notes, and snippets.

@xeoncross
Created May 9, 2018 14:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xeoncross/1e3eb005d02dd61feeaa527441ed505b to your computer and use it in GitHub Desktop.
Save xeoncross/1e3eb005d02dd61feeaa527441ed505b to your computer and use it in GitHub Desktop.
How would you find permutations of all possible 1) lengths, 2) orders, and 3) from multiple lists?
import itertools
# Permutations of multiple lists
# https://stackoverflow.com/q/2853212
s=[ [ 'a', 'b', 'c'], ['d'], ['e', 'f'] ]
for l in list(itertools.product(*s)):
print(l)
# Permutations of all possible sizes of a list
# https://stackoverflow.com/a/5898031/99923
s = [1, 2, 3]
for L in range(0, len(s)+1):
for subset in itertools.permutations(s, L):
print(subset)
# Permutations of all possible lenghts and orders of a multiple lists
# https://stackoverflow.com/q/50242147/99923
s=[ [ 'a', 'b', 'c'], ['d'], ['e', 'f'] ]
s = [x for y in s for x in y]
for L in range(0, len(s)+1):
for subset in itertools.permutations(s, L):
print(subset)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment