Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Duplicate Zeros by colinmcnicholl
def duplicate_zeros(donuts: list) -> list:
result = []
for el in donuts:
if el != 0:
result.append(el)
else:
result += [el] * 2
return result
print("Example:")
print(duplicate_zeros([1, 0, 2, 3, 0, 4, 5, 0]))
assert duplicate_zeros([1, 0, 2, 3, 0, 4, 5, 0]) == [1, 0, 0, 2, 3, 0, 0, 4, 5, 0, 0]
assert duplicate_zeros([0, 0, 0, 0]) == [0, 0, 0, 0, 0, 0, 0, 0]
assert duplicate_zeros([100, 10, 0, 101, 1000]) == [100, 10, 0, 0, 101, 1000]
print("The mission is done! Click 'Check Solution' to earn rewards!")
Sept. 25, 2022
Comments: