Solution Review: Count with Dictionary
The solution to the 'Count with Dictionary' challenge.
We'll cover the following
from collections import defaultdictfrom collections import OrderedDictdef count_letters(message):d = defaultdict(int) # Making dictionary with intfor letter in message:d[letter] += 1 # Adding 1 with every repetition# Sorting on the basis of valuesreturn OrderedDict(sorted(d.items(), key = lambda t:t[1]))print(count_letters('Welcome to Educative'))
Get hands-on with 1400+ tech skills courses.