0

I need to create a function that will be passed a list and will create a new list with all the subsets of the the original list. I have to write it all from scratch, so no importing from itertools.

For Example:

the list given be like [1,2,3] and I want an output like

[[1],[2],[3],[1,2],[2,3],[1,3],[1,2,3],[]]
Allan
  • 12,117
  • 3
  • 27
  • 51
JustBeginning
  • 33
  • 1
  • 4
  • 2
    have you tried something so far? – Allan Dec 08 '17 at 05:27
  • 2
    If you have to write it all from scratch, it's probably best that **you** write it instead of doing some `import code from StackOverflow`. However, if you have any specific question about a part that you don't understand, please make a specific question. – Davy M Dec 08 '17 at 05:27
  • I guess, this is the duplicate of https://stackoverflow.com/questions/1482308/whats-a-good-way-to-combinate-through-a-set and https://stackoverflow.com/questions/41626379/python-power-set-of-a-list – GadaaDhaariGeek Dec 08 '17 at 05:58
  • Possible duplicate of [what's a good way to combinate through a set?](https://stackoverflow.com/questions/1482308/whats-a-good-way-to-combinate-through-a-set) – GadaaDhaariGeek Dec 08 '17 at 05:58

1 Answers1

2
from itertools import combinations
s = set([1,2,3])
sum(map(lambda r: list(combinations(s, r)), range(1, len(s)+1)), [])

Producing tuples value but it close enough for you.