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


Good job! Before we wrap this section up, let's have a quick summary and a quiz. What did we learn?

  1. Nested lists are lists within lists. They may or may not be rectangular and can consist of as many dimensions as needed, but two-dimensional nested lists are the most popular.
  2. To access a specific element in a nested list, use as many square bracket pairs as there are dimensions in the list:
    nested_list = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
    nested_list[1][2] # returns 6
  3. To iterate over the values of a nested list, use:
    for row in nested_list:
      for cell in row:
  4. To iterate over the indexes of a nested list, use:
    for i in range(len(nested_list)):
      for j in range(len(nested_list[i])):
  5. To modify the elements of a nested list, iterate over the indexes, not the values.
  6. To quickly copy a nested list, use:
    import copy
    new_nested_list = copy.deepcopy(nested_list)
  7. How about that short quiz now?


Click Next exercise to continue.