• Sorted function explanation please ? :)

Question related to mission The Most Wanted Letter


Hi all,

I managed to solve the problem using the previous posts from this forum. My code is:

def checkio(text): text = str.lower(text) textnospace = text.replace(' ','') itemcount = [] for char in textnospace: if char.isalpha(): itemcount.append((char, textnospace.count(char))) itemcount.sort(key=lambda x: (-x[1], x[0])) return item_count[0][0] ​

Prob not the best way to write it, but it works.

My question is: what does "x: (-x[1], x[0])" do for the sorting? I understand the idea of sorting the list by the number of counts for each letter, and return the first value in this new sorted list, but cannot figure what x stands for or why the minus coordinate 1 mean?

Any help would be greatly appreciated. Thanks!