PythiloMedium · 25 min · Task 56 of 100 · progress kept in this browser

Top frequent values

Return up to k distinct integers ordered by decreasing frequency, breaking ties by increasing value. k is nonnegative.

from collections import Counter
counts = Counter([3, 3, 2, 2, 1])
print(sorted(counts, key=lambda x: (-counts[x], x)))
Your task

Return up to k distinct integers ordered by decreasing frequency, breaking ties by increasing value. k is nonnegative.