Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
nested lambda solution in Clear category for Frequency Sorting by zshlab
frequency_sorting = lambda numbers: sorted(numbers, key=lambda x: (-numbers.count(x), x))
print("Example:")
print(list(frequency_sorting([1, 2, 3, 4, 5])))
# These "asserts" are used for self-checking
assert list(frequency_sorting([1, 2, 3, 4, 5])) == [1, 2, 3, 4, 5]
assert list(frequency_sorting([3, 4, 11, 13, 11, 4, 4, 7, 3])) == [
4,
4,
4,
3,
3,
11,
11,
7,
13,
]
print("The mission is done! Click 'Check Solution' to earn rewards!")
Feb. 16, 2025
Comments: