Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for Sort Except Zero by HubiJohn98
from typing import Iterable
def except_zero(items: list) -> Iterable:
list_of_value_index_tuples = list(enumerate(items))
list_without_zeros = []
for digit in items:
if digit != 0:
list_without_zeros.append(digit)
new_list = sorted(list_without_zeros)
for index, value in list_of_value_index_tuples:
if value == 0:
new_list.insert(index, value)
return new_list
print("Example:")
print(list(except_zero([5, 3, 0, 0, 4, 1, 4, 0, 7])))
assert list(except_zero([5, 3, 0, 0, 4, 1, 4, 0, 7])) == [1, 3, 0, 0, 4, 4, 5, 0, 7]
assert list(except_zero([0, 2, 3, 1, 0, 4, 5])) == [0, 1, 2, 3, 0, 4, 5]
assert list(except_zero([0, 0, 0, 1, 0])) == [0, 0, 0, 1, 0]
assert list(except_zero([4, 5, 3, 1, 1])) == [1, 1, 3, 4, 5]
assert list(except_zero([0, 0])) == [0, 0]
print("The mission is done! Click 'Check Solution' to earn rewards!")
Dec. 13, 2022
Comments: