freq = {3: 3, 2: 6, 1: 4} k = 2 sort_orders = {k: freq[k] for k in sorted(freq, key=freq.get, reverse=True)[:k]} print(sort_orders) # Output {2: 6, 1: 4}
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter