Created
May 9, 2018 14:47
-
-
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?
This file contains 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 | |
# 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