Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Optional ascending information solution in Clear category for Sort Sorted Groups by Phil15
from itertools import pairwise
def sorted_groups(items: list[int]) -> list[int]:
ascending: bool | None = None
groups = [items[:1]]
for prev, item in pairwise(items):
if prev != item:
if ascending is None:
# New ascending information.
ascending = prev < item
elif ascending != (prev < item):
# New group, without ascending information.
groups.append([])
ascending = None
groups[~0].append(item)
groups.sort()
return sum(groups, [])
Sept. 13, 2022
Comments: