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>If you just want to move all zeros in the list to the end, try:</p>

<pre><code>def move_zeros(array):
    result = [x for x in array if x is not 0]
    return result + [0]*(len(array)-len(result))
</code></pre>

<p>Using recursion:</p>

<pre><code>def move_zeros(array, n=None):
    if n is None:
        n = len(array) - 1
    if n &lt; 0:
        # no more to process
        return array
    if array[n] is 0:
        # move this zero to the end
        array.append(array.pop(n))
    return move_zeros(array, n-1)
</code></pre>

python recursion runtime-error