def char_count(text): """ counts the number of occurances of ascii letters - 65<=ord(ch)<=90 (capital) or 97<=ord(ch)<=122, in a text. Returns a list of pairs, where first elements in pairs are the lower case letters, and second elements being the counts """ d = {} # initializing an empty dictionary for ch in text: ch=str.lower(ch) if ord(ch)ord("z"): # not a letter continue else: # incrementing letter count by 1 if ch in d: d[ch]=d[ch]+1 else: d[ch]=1 lst=list(d.items()) # truning dictionary into list return sorted(lst, key=lambda pair: pair[1], reverse=True) # sort high to low by counts # return sorted(lst, key=lambda pair: -pair[1]) # sort high to low by counts