Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
One-liner solution in Clear category for Move Zeros by H0r4c3
from typing import Iterable
def move_zeros(items: list[int]) -> Iterable[int]:
return [item for item in items if item != 0] + [0]*items.count(0)
print("Example:")
print(list(move_zeros([0, 1, 0, 3, 12])))
# These "asserts" are used for self-checking
assert list(move_zeros([0, 1, 0, 3, 12])) == [1, 3, 12, 0, 0]
assert list(move_zeros([0])) == [0]
print("The mission is done! Click 'Check Solution' to earn rewards!")
Dec. 10, 2022