Source code for kyu_5.moving_zeros_to_the_end.move_zeros

#  Created by Egor Kostan.
#  GitHub: https://github.com/ikostan
#  LinkedIn: https://www.linkedin.com/in/egor-kostan/


[docs]def move_zeros(array: list): """ An algorithm that takes an array and moves all of the zeros to the end, preserving the order of the other elements. :param array: :return: """ moving_zero = True while moving_zero: moving_zero = False for i, a in enumerate(array): if a == 0 and array[i:].count(0) != len(array[i:]) and a is not False: del array[i] array.append(0) moving_zero = True break return array