If you’re dropping code to the forums or posting text that uses symbols that markdown interprets then How do I format code in my posts? can help keep it in check.
It is just referring to how many integer numbers can be represented by a single binary digit, the examples show integer 0 and integer 1 represented in binary. Then, with two binary digits you can represent a total of 4 integer numbers and so on.
Not sure if I’ve interpreted you correctly but I’ll give it a shot.
If you’ve reduced my_list down to a single element then you’re passing an empty slice-
x = [3] # slicing outside the index range of a list with one element-
x[1:] == [] # empty list
In your code that call to power_set will hit the base case conditional about if len(my_list) == 0 and return [] at that point because you passed an empty list as the argument.
To put it another way-
if len(my_list) == 1:
power_set(my_list[1:]) == []
So it moves forwards because you hit the base case.
As an Electrical Engineer, the iterative solution that uses binary digits to map to the power set is much more intuitive and easily understandable. It’s not at all complicated if you understand what’s going on.
The recursive solution is still a mystery to me.
Iterative solution using binary digit mapping
power_set = ['a', 'b', 'c']
‘a’ → position 1 ‘b’ → position 2 ‘c’ → position 3