Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Introduction to nested lists
2. Nested lists – introduction
Iterating over nested lists
Modifying nested lists
Working with multiple lists
Summary

Instruction

Perhaps you're wondering what nested lists actually are. Let's use an example to find out.

Suppose we organized a fundraising event that raised funds in four different places on three different days. We could store the amounts collected in each place on each day in separate lists, like this:

donations_day_1 = [345.0, 287.80, 119.27, 329.30]
donations_day_2 = [294.25, 349.0, 178.90, 262.34]
donations_day_3 = [401.0, 456.45, 289.43, 319.27]

This, however, is a very verbose and inefficient way of storing data. It's better to use a nested list:

donations = [
  [345.0, 287.80, 119.27, 329.30],
  [294.25, 349.0, 178.90, 262.34],
  [401.0, 456.45, 289.43, 319.27]
]

This is a nested list. As you can see, each list has now become an element in an outer list. Single lists are separated with commas, just like any other type of element in a list.

Exercise

During a Python Hackathon, development teams were asked to create four applications. There were three prizes (1st, 2nd, and 3rd) awarded for each of the four applications. You can see the results in the template code: each list contains the names of the teams that won the first, second, and third place prizes.

Your task is to create a single variable named hackathon_results. It should be a nested list containing all three (1st, 2nd, and 3rd) winners for all four apps.

Stuck? Here's a hint!

Your solution should have the following structure:

hackathon_results = [
  [...],
  [...],
  [...],
  [...]
]