Return sorted list of first n elements from the dictionary

PHOTO EMBED

Wed Oct 19 2022 07:56:57 GMT+0000 (Coordinated Universal Time)

Saved by @hasib404 #python

freq = {3: 3, 2: 6, 1: 4}
k = 2

sort_orders = [k for k in sorted(freq, key=freq.get, reverse=True)[:k]]
print(sort_orders)

# Output [2, 1]
content_copyCOPY

https://stackoverflow.com/questions/20944483/python-3-sort-a-dict-by-its-values