Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Sort Except Zero by Wartem
from typing import Iterable
def except_zero(items: list) -> Iterable:
'''
Create a list with only positives. Sort it.
Find all indexes containing 0.
Insert 0 at these indexes in the list of positives.
'''
res = sorted(filter(lambda x: (x != 0), items))
zero_i = [i for i, x in enumerate(items) if x == 0]
for i in zero_i:
res.insert(i, 0)
return res
June 4, 2022
Comments: