how to use recursion to combine the two function to one ?I know it's an answer of "move_zeros", But here I post just want to learn how to use recursion and solve problems with recursion.
func 1
def move_zeross(array):
for i in range(len(array)):
if array[i] is not False and array[i] == 0:
array.pop(i)
array.append(0)
return array
func 2
def move_zeros(array):
for i in range(len(array)):
if array[i] is not False and array[i] == 0:
move_zeross(array)
return array
I have tried like below, but RuntimeError
happens:
RuntimeError: maximum recursion depth exceeded in cmp
Here's the combined code:
def move_zeros(array):
for i in range(len(array)):
if array[i] is not False and array[i] == 0:
array.pop(i)
array.append(0)
move_zeros(array)
return array