I'm trying to wrap my head around the concept of recursion and has the following queries with regard to the output of the below code:
def subsetsofSet(input_list, set_list=None):
print "IN input_list: {0}".format(input_list)
if not input_list:
return
input_list.pop()
subsetsofSet(input_list)
print "RETURN input_list: {0}".format(input_list)
subsetsofSet([1,2,3])
Output is as below:
IN input_list: [1, 2, 3]
IN input_list: [1, 2]
IN input_list: [1]
IN input_list: []
RETURN input_list: []
RETURN input_list: []
RETURN input_list: []
Why is the RETURN input_list
always empty? Shouldn't it be displayed in the reverse manner of the IN input_list
? Appreciate any help in understanding this?