-1

The dictionary contains all the alphabets as keys and their occurrence (in numbers) as values of the keys. I have to get the 3 most occurred alphabets of them. Attaching the dictionary for better understanding.

{'a': 2, 'b': 1, 'c': 4, 'd': 5, 'e': 6, 'f': 7, 'g': 9, 'h': 9, 'i': 10, 'j': 3, 'k': 0, 'l': 0, 'm': 0, 'n': 0, 'o': 0, 'p': 0, 'q': 0, 'r': 0, 's': 0, 't': 0, 'u': 0, 'v': 0, 'w': 0, 'x': 0, 'y': 0, 'z': 0}
shubham
  • 182
  • 1
  • 1
  • 8

1 Answers1

0
import operator
input_data = {'a': 2, 'b': 1, 'c': 4, 'd': 5, 'e': 6, 'f': 7, 'g': 9, 'h': 9, 'i': 10, 'j': 3, 'k': 0, 'l': 0, 'm': 0, 'n': 0, 'o': 0, 'p': 0, 'q': 0, 'r': 0, 's': 0, 't': 0, 'u': 0, 'v': 0, 'w': 0, 'x': 0, 'y': 0, 'z': 0}

# Sort it
sorted_data = sorted(input_data.items(), key=operator.itemgetter(1))

# Get last 3 results
print(sorted_data[-3:])
Wimanicesir
  • 4,606
  • 2
  • 11
  • 30