For instance, calling the function on
n = 1
would return: [[1]]
n = 12
would return: [[1, 2]]
n = 123
would return: [[1, 2, 3], [12, 3], [1, 23]]
n = 1234
would return: [[1, 2, 3, 4], [1, 234], [1, 2, 34], [1, 23, 4], [12, 3, 4], [123, 4], [12, 34]]
I have tried a recursive approach, but I don't seem to be getting any closer to a solution. My attempted solution used modulo, floor division, and treated n as an integer, but I understand this can be done with strings as well.
def subs(n):
if n < 10:
return n
else:
lst = []
lst.append([n])
lst.extend([[subs(n//10), subs(n % 10)]])
return lst