Move zeros to the end
Return a new list with all numeric zeros last, preserving the order of all other numbers.
items = [0, 1, 0, 3]
nonzero = [x for x in items if x != 0]
print(nonzero, len(items)-len(nonzero))Reason about the state
Collect nonzero values first and append exactly the missing number of zeros. This is stable and linear in the input size. Before writing code, identify what each variable means after one iteration. Walk through the example and explain why the next transition preserves that meaning. Then check the smallest permitted input and a case with repeated values. A correct answer follows the contract for every input, including the boundary cases in the checks. Keep any input mutation within the stated rules; return a fresh result when the task asks for one.
Your task
Return a new list with all numeric zeros last, preserving the order of all other numbers.
The explanation opens here once every check passes.