Created
July 30, 2020 08:27
-
-
Save manuelep/f8ccee566eab8eb12860bf22f950f9a1 to your computer and use it in GitHub Desktop.
all permuted multiple combinations af a list of values
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 | |
| from more_itertools import powerset | |
| def all_possible_multivalue(*values): | |
| values_ = list(itertools.permutations(values)) | |
| values = list(set(sum([list(powerset(vv)) for vv in values_], []))) | |
| return values | |
| print(sorted(all_possible_multivalue(1,2,3,), key=lambda v: (len(v), v,))) | |
| # [(), (1,), (2,), (3,), (1, 2), (1, 3), (2, 1), (2, 3), (3, 1), (3, 2), (1, 2, 3), (1, 3, 2), (2, 1, 3), (2, 3, 1), (3, 1, 2), (3, 2, 1)] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment