Reputation: 11
New with programming and spend a lot of time on trying to understand this recursive function, but I just can't visualize it. It's about the subsetsRecur
function. Anyone have a simple understandable explanation?
class py_solution:
def sub_sets(self, sset):
return self.subsetsRecur([], sorted(sset))
def subsetsRecur(self, current, sset):
if sset:
return self.subsetsRecur(current, sset[1:]) + self.subsetsRecur(current + [sset[0]], sset[1:])
return [current]
print(py_solution().sub_sets([4,5,6]))
Upvotes: 0
Views: 126