Faced a task on the codebook and seemed to be solved if it were not for one thing! The task itself is simple to the point of insanity, you need in the list everything that is 0 (zero) sent to the end of the line. it works

def move_zeros(array): for i in array: array.append(array.pop(array.index(0))) if array.index != 0: continue print(array) # [9, -10, {}, True, 1, 2, 'a', 1, 1, [], None, 3, 'z', 1, 0, 0, 0, 0, 0, 0, 0] 

But until False is slipped into the data.

 if array.index != 0 and array.index is False: 

I still get something like

 [9, -10, {}, True, 1, 2, 'a', 1, 1, [], None, 3, 'z', 1, 0, 0, 0, False, 0, 0, 0, 0] 

    1 answer 1

     from math import isclose l = [.0, .001, -.0, 9, -10, {}, True, 1, 2, 'a', 1, 1, [], None, 3, 'z', 1, 0, 0, 0, False, 0, 0, 0, 0] def iszero(val): return val is 0 or (isinstance(val, float) and isclose(val, 0)) # подсчет количества нулей zeros_cnt = sum(map(iszero, l)) # фильтрация списка от нулей: l = [i for i in l if not iszero(i)] # вставка нулей в конец списка l += [0] * zeros_cnt 
    • Thank you, plowing! but if you slip 0.0 then a bummer - Vadim
    • one
      @Vadim, updated the answer. - mkkik