WeCodeAcademy

Practice: Anagrams and Word Counts

Dictionaries and sorting solve many text puzzles. Two words are anagrams if they use the same letters: listen and silent. Sorting the letters of each word gives the same key, so a dictionary can group all anagrams together. For counting, a dictionary of word to count (or collections.Counter) does the job in one pass.

Examplepython
Open in editor »
Quick check

Why does sorting the letters of a word help find anagrams?

Your turn: write the code

Count how many times each word appears (use a dictionary) and print the word that appears most often.

Finish the quick check (and any code exercise) to complete this lesson, or mark it done yourself.

Tip: use the left and right arrow keys to move between lessons.