# Task
For the given set `S` its powerset is the set of all possible subsets of `S`.

Given an array of integers nums, your task is to return the powerset of its elements.

Implement an algorithm that does it in a depth-first search fashion. That is, for every integer in the set, we can either choose to take or not take it. At first, we choose `NOT` to take it, then we choose to take it(see more details in exampele).

# Example

For `nums = [1, 2]`, the output should be `[[], [2], [1], [1, 2]].`

Here's how the answer is obtained:
```
don't take element 1
----don't take element 2
--------add []
----take element 2
--------add [2]
take element 1
----don't take element 2
--------add [1]
----take element 2
--------add [1, 2]```

For `nums = [1, 2, 3]`, the output should be 

`[[], [3], [2], [2, 3], [1], [1, 3], [1, 2], [1, 2, 3]]`.

# Input/Output

`[input]` integer array `nums`

Array of positive integers, `1 ≤ nums.length ≤ 10`.

[output] 2D integer array

The powerset of nums.

Difficulty: EASY
Starter code: def powerset(nums):
	

Solutions:
from itertools import compress, product

def powerset(a):
	return [list(compress(a, p)) for p in product((0, 1), repeat=len(a))]


def powerset(nums):
	if not nums:
		return [[]]
	l = powerset(nums[1:])
	a = nums[0]
	return l + [[a] + q for q in l]


def powerset(nums):
	t = []
	for i in range(2 ** len(nums)):
		t.append([nums[k] for (k, z) in enumerate(bin(i)[2:].zfill(len(nums))) if z == '1'])
	return t


def powerset(s):
	if not s:
		return [[]]
	result = powerset(s[1:])
	return result + [[s[0]] + subset for subset in result]


powerset = lambda a: [[n for (i, n) in enumerate(a) if b >> len(a) - i - 1 & 1] for b in range(1 << len(a))]


powerset = lambda n: (lambda c: c + [[n[0]] + e for e in c])(powerset(n[1:])) if n else [[]]


def powerset(nums):
	n = len(nums)
	return [[nums[i] for (i, item) in enumerate(bin(mask)[2:].rjust(n, '0')) if item == '1'] for mask in range(2 ** n)]


def powerset(nums):
	if len(nums) == 1:
		return [[], nums]
	s = powerset(nums[1:])
	for a in s[:]:
		s.append([nums[0]] + a)
	return s


def powerset(nums):
	l = len(nums)
	return [[x for (j, x) in enumerate(nums) if i & 1 << l - j - 1] for i in range(2 ** l)]


def powerset(nums):
	if len(nums) == 0:
		return [[]]
	sub = powerset(nums[1:])
	first = nums[:1]
	buffer = []
	for ele in sub:
		buffer.append(first + ele)
	return sub + buffer