Is there any methods to combine the two function to one
<p>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.</p>

<p>func 1</p>

<pre><code>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
</code></pre>

<p>func 2</p>

<pre><code>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
</code></pre>

<p>I have tried like below, but <code>RuntimeError</code> happens:</p>

<pre><code>RuntimeError: maximum recursion depth exceeded in cmp
</code></pre>

<p>Here's the combined code:</p>

<pre><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
</code></pre>

<p>A different recursive approach:</p>

<pre><code>def move_zeros(array):
    if array:
        head, tail = array[0], move_zeros(array[1:])

        if head is 0:
            array = tail
            array.append(head)
        else:
            array = [head]
            array.extend(tail)

    return array
</code></pre>

<p>Does more list operations than acw1668's solution but is less index oriented.</p>

python recursion runtime-error