Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
MySolutionDuplicateZeros solution in Clear category for Duplicate Zeros by jemg2030
from collections.abc import Iterable
def duplicate_zeros(donuts: list[int]) -> Iterable[int]:
# your code here
new_donuts = []
for num in donuts:
new_donuts.append(num)
if num == 0:
new_donuts.append(0)
return new_donuts
print("Example:")
print(list(duplicate_zeros([1, 0, 2, 3, 0, 4, 5, 0])))
# These "asserts" are used for self-checking
assert list(duplicate_zeros([1, 0, 2, 3, 0, 4, 5, 0])) == [
1,
0,
0,
2,
3,
0,
0,
4,
5,
0,
0,
]
assert list(duplicate_zeros([0, 0, 0, 0])) == [0, 0, 0, 0, 0, 0, 0, 0]
assert list(duplicate_zeros([100, 10, 0, 101, 1000])) == [100, 10, 0, 0, 101, 1000]
print("The mission is done! Click 'Check Solution' to earn rewards!")
March 5, 2023