Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
"Move Zeros" solution in Uncategorized category for Move Zeros by Mateusz_Wryszcz
from typing import Iterable
def move_zeros(items: list[int]) -> Iterable[int]:
return [x for x in items if x != 0] + [x for x in items if x == 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. 30, 2022