From the course: Programming Foundations: Data Structures (2023)

Unlock the full course today

Join today to access over 24,400 courses taught by industry experts.

Create a list in Python

Create a list in Python

- [Instructor] We've talked about arrays in theory, but now it's time to practice them in the Python programming language with a list. Let's say we want to compute the average number of pets each student has in a class. This calls for a data structure because we need a way to store and access each student's number of pets as well as a way to compute the average. The first thing we'll do is create a list of numbers. We'll call it student_pet_count_list. Each number in this list represents the number of pets a specific student has. Here we're creating and initializing a list with values. While technically you can put data of different types in the same list, it's mostly discouraged to avoid confusion and wasting space. Typically, collections are used to store data of similar types. Now, back to our example. In order to compute the average number of pets each student has, we need to know how many students are in the class.…

Contents