Skip to content

Instantly share code, notes, and snippets.

@manuelep
Created July 30, 2020 08:27
Show Gist options
  • Select an option

  • Save manuelep/f8ccee566eab8eb12860bf22f950f9a1 to your computer and use it in GitHub Desktop.

Select an option

Save manuelep/f8ccee566eab8eb12860bf22f950f9a1 to your computer and use it in GitHub Desktop.
all permuted multiple combinations af a list of values
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