pyassistant

Move zeros to the end of a list

Write a function that takes a list of integers and returns a new list where all zeros are moved to the end while preserving the relative order of the non-zero elements. The relative order among zeros does not matter (they can appear in any order at the end). Do not modify the input list in-place; return a new list.

Example:

Input:
([0, 1, 0, 3, 12],)
Output:
[1, 3, 12, 0, 0]

Make sure you return your solution, don't print!

AI

Bot

Trying to solve my challenge? Ask if you must, or press the purple button so I can analyze your code.