15.2. What is a List?

A list is just an ordered collection of items - you probably use lists all the time. People often make a list before they go shopping or a list of things to do. Although they may not explicitly number the items, there is always a first thing in a list, and a second, and so on:

a shopping list

A shopping list

A list in Python is a collection of values. We can write a list by enclosed values in [ and ] and separating them by commas, like [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]. The values in a list can be any type of data, and can even be a mix of types of data (though it is often best to avoid complicating things by mixing different types of data in one list).

Recall that the for loop will automatically repeat code for each value in a list. That means if I want to greet each name in the nameList I could do:

Putting items into a list makes it easier to process them all in a similar way without repeating chunks of code multiple times. Complete this algorithm for the problem discussed on the last page of finding the highest quiz score.

The following program should loop through all the scores and compare them to the highest score we have seen so far. (When we start, the highest score we have seen is 0.) If a score is higher than the highest score we have seen, we need to update the highest value. When we are done looping through the scores, we will print the highest value we saw.

You have attempted of activities on this page