Write an algorithm that takes an list and moves all of the zeros to the end, preserving the order of the other elements.

move_zeros([False,1,0,1,2,0,1,3,"a"]) # returns[False,1,1,2,1,3,"a",0,0]



For test exemples:

[1,2,0,1,0,1,0,3,0,1]

[9,0.0,0,9,1,2,0,1,0,1,0.0,3,0,1,9,0,0,0,0,9]

["a",0,0,"b","c","d",0,1,0,1,0,3,0,1,9,0,0,0,0,9]

["a",0,0,"b",None,"c","d",0,1,False,0,1,0,3,[],0,1,9,0,0,{},0,0,9]

[0,1,None,2,False,1,0]

["a","b"]

["a"]

[0,0]

[0]

[False]

[]

On Python
Please enter comments
Please enter your name.
Please enter the correct email address.
You must agree before submitting.

Answers & Comments


Copyright © 2024 SCHOLAR.TIPS - All rights reserved.