def subs(l):
if l == []:
return [[]]
x = subs(l[1:])
return x + [[l[0]] + y for y in x]
1) I am trying to understand working of the above code
2) If l = [1,2,3] at the end of the recursion we will get an empty list of list
3) In last next iteration we will be given the result to the x will be 3
(I am thinking it will go to the next step which is return)
4) In these returns I am thinking it will add return x + [[l[0]] + y for y in x] should return (3,3).
5) By ending of these step the answer should be (3,3).
The final answer according to be at the second step must be [[],[3,3]].
But the code is printing a different answer.
o/p
[], [3]]
Can any one explain where my assumption went wrong and how return x + [[l[0]] + y for y in x] these steps are working?

l=[3], thenx=[[]]. In step 4, the result ofreturn x + [[l[0]] + y for y in x]will be[[]] + [[3] + []]which is[[], [3]]