I have a coding project and here is my code
from operator import itemgetter
# 1. Get input
# 2. Split each letter and number
# 3. Find the 5 most frequent numbers
# 4. Find the letter or number and print the answers
countcount = 0
N = 5
# Overview code
input123 = str(input('Please enter your letters \n')).replace(" ", "")
test_list = str({i :input123.count(i) for i in set(input123)})
# Get Top N elements from Records
# Using sorted() + itemgetter()
res = sorted(test_list, key = itemgetter(0), reverse = True)[:N]
# printing result
print("The top N records are : " + str(res))
print(str(res))
As you can see, I want to enter a random string and get the top 5 letter/numbers. Right now if I enter qqqqqqwwwwweeeerrrtty, 2 of the answers would be {
and }
while the rest would be either q,w,e,r,t or y. Am I using itemgetter
wrongly?