I have to iterate over a list containing random values like
["a",0,0,"b",None,"c","d",0,1,False,0,1,0,3,[],0,1,9,0,0,{},0,0,9]
and move all zeroes(0) to the end of the list preserving the order of other elements. This is my code:
for i in range(len(array)):
if array[i] ==0 and array[i] is not False:
array.append(array[i])
array.remove(array[i])
return array
The code works fine but it treats 'False' as 0 so the output doesn't match to the desired one. I've tried searching for the answer and have implemented them to my code like using 'is' and 'is not', but they don't seem to be working for me. What else can I do?
My Output: ['a', 'b', None, 'c', 'd', 1, 1, 3, [], 1, 9, {}, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
however the output should be ['a', 'b', None, 'c', 'd', 1, False, 1, 3, [], 1, 9, {}, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]