Working with Nested Lists in Python
๐ Scenario: You are organizing a small library's book shelves. Each shelf holds a list of book titles. The library has three shelves.
๐ฏ Goal: You will create a nested list representing the shelves and their books, then count how many books are on each shelf, and finally print the counts.
๐ What You'll Learn
Create a nested list called
library_shelves with exactly three inner lists, each containing the exact book titles specified.Create a list called
book_counts to store the number of books on each shelf.Use a
for loop with the variable shelf to iterate over library_shelves.Append the length of each
shelf to book_counts.Print the
book_counts list.๐ก Why This Matters
๐ Real World
Nested lists help organize grouped data like shelves of books, classrooms of students, or menus with categories.
๐ผ Career
Understanding nested lists is important for data organization, processing multi-level data, and working with complex datasets in many programming jobs.
Progress0 / 4 steps