0

I have a python list as below

l = ['water', 'park', 'kit']

To get all combinations of these elements, I'm using this

p = list(itertools.permutations(l))

For which I get result as below:
[('water', 'park', 'kit'), ('water', 'kit', 'park'), ('park', 'water', 'kit'), ('park', 'kit', 'water'), ('kit', 'water', 'park'), ('kit', 'park', 'water')]

I also need partial combinations of the elements as well, something like below:
[('water'), ('water', 'kit'), ('park',), ('park', 'kit'), ('kit', 'park')]

Is there a way to populate these combinations as well?

N Raghu
  • 706
  • 4
  • 13
  • 26
  • 3
    Does this answer your question? [How to get all subsets of a set? (powerset)](https://stackoverflow.com/questions/1482308/how-to-get-all-subsets-of-a-set-powerset) – BcK Mar 17 '21 at 12:30
  • thanks for pointing out to the right post. – N Raghu Mar 17 '21 at 12:39

0 Answers0