Group Words by First Letter
Intermediate · Write the code · from Working with Nested Lists, Dicts, and Complex Data Structures
From the lesson: Working with Nested Lists, Dicts, and Complex Data Structures
Think about a school. A school has classrooms. Each classroom has students. Each student has a name, an age, and a list of grades. That's data inside data inside data - nested data.
Read the lessonGroup the words by their first letter into a dictionary. Then print each group on a separate line in the format: letter: [words]
Print the letters in sorted order.
words = ['ant', 'bear', 'apple', 'bat', 'cat', 'cow']
# Group by first letter and print
More nested data exercises
- Access Nested List ItemsBeginner
- Predict the Output: Nested Dict AccessBeginner
- Find the Highest ScorerIntermediate
- Fix the Bug: Nested List TrapIntermediate
- Calculate Class AveragesAdvanced
All Python exercises · 50 practice problems · Data Structures quiz