Lists

In data science, it is often more useful to store data in a single place. We can accomplish this by using a variety of data structures in our program. The first data structure we will examine in depth is the list, a sequence data structure that typically contains values of the same type. Although we will be discussing lists in more detail within this section of the text, many of the capabilities shown in this section apply to all sequence types.

Lists typically store homogeneous data, that is, values of the same data type. Consider the list c, which contains five integer elements:

c = [-45, 6, 0, 72, 1543]

Lists may store heterogeneous data, that is, data of many different types. For example, the following list contains a student’s first name (a string), last name (a string), grade point average (a float) and graduation year (an int):

student = ['Abdulaahi', 'Mohamed', 3.4, 2010]

Lists are mutable. In other words, their elements can be modified. Read the next page of this section to learn more about how you can change the elements in a list. You’ll also see that you can insert and delete elements, changing the list’s length.