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 - Python Tutorial
From the course: Programming Foundations: Data Structures (2023)
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
-
-
-
-
What is an array?3m 31s
-
(Locked)
Create a list in Python2m 27s
-
(Locked)
Retrieve data from a list in Python4m 26s
-
(Locked)
Mutate a list in Python2m 57s
-
(Locked)
Multidimensional lists7m 15s
-
(Locked)
Tuples in Python2m 45s
-
(Locked)
Search array-like structures4m 47s
-
(Locked)
Sort array-like structures5m 1s
-
(Locked)
Challenge: Find the second smallest item1m 35s
-
(Locked)
Solution: Find the second smallest item4m 26s
-
(Locked)
When to use array-like structures1m 15s
-
-
-
-
-
-
-