I'm writing a function to move 0's to the end of a list, but when a False value is in the list, it converts it to 0 and moves it to the end as well.
I've tried many variations of if statements including:
if i == 0
if type(i) != bool and i == 0
if str(i) == '0'
def move_zeros(array):
for i in array:
if str(i) == '0' and str(i) != 'False':
array.remove(i)
array.append(0)
return array
In case of [0,1,None,2,False,1,0]
, I expected the function to return [1,None,2,False,1,0,0]
, but it returned [1,None,2,1,0,0,0]
instead.