Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Two different results

The below code provides the results I want (move the number to the front and 0 to the end of the list) on programminghero’s playground. When I put it in a jupyter notebook the result is all 0’s.
So, move_zero([0,1,0,2,0,3,0,5]) should return [1,2,3,5,0,0,0,0] but in jupyter it returns [0,0,0,0,0,0,0,0].

def move_zero(lst):

    new_list = lst
    counter = 0
    for each in new_list:
        if each == 0:
            new_list.pop(counter)
            new_list.append(0)
            counter -= 1
        counter += 1
    return new_list
        
print(move_zero([0,1,0,2,0,3,0,5]))

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

redacted — code had bug, not sure why it was accepted lol

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading