The output of this code is: [[2, 2, 2, 2], [0, 0, 0], [0, 0], [0]]
def shrink(numbers, return_list=[]):
n1 = [(x, numbers[i + 1]) for i, x in enumerate(numbers) if i < len(numbers) - 1]
n2 = [x[1] - x[0] for x in n1]
return_list.append(n2)
if (len(n2) > 1):
return shrink(n2, return_list)
else:
return return_list
print(shrink([2, 4, 6, 8, 10]))
Input: 2 4 6 8 10
The output of this inputted list in this code is: [[2, 2, 2, 2], [0, 0, 0], [0, 0], [0], [2, 2, 2, 2], [0, 0, 0], [0, 0], [0]]
as you can see, the recursion repeats.
def shrink(numbers, return_list=[]):
n1 = [(x, numbers[i + 1]) for i, x in enumerate(numbers) if i < len(numbers) - 1]
n2 = [x[1] - x[0] for x in n1]
return_list.append(n2)
if (len(n2) > 1):
return shrink(n2, return_list)
else:
return return_list
a = input()
b = a.split()
for i in range(len(b)):
b[i] = int(b[i])
c = shrink(b)
print(shrink(b))
Please help me to debug/overhaul my second code in order to have an output same as the first code presented. I am only a high school student.