From the course: Programming Foundations: Data Structures
Unlock the full course today
Join today to access over 24,700 courses taught by industry experts.
Mutate a list in Python - Python Tutorial
From the course: Programming Foundations: Data Structures
Mutate a list in Python
- [Instructor] Sometimes you may need to modify or update the data in your list. For example, let's say the school had a reading competition and a few students read more books, so you need to update their book counts. We'll say the first student read three more books, the second student read one more book, and the last student read two more books. To reflect this, we'll need to modify the values in our student books list. Modifying an item is very similar to accessing one. We'll use the list name, student_books_list, square brackets, and then the index to specify which entry we want to change. In this case, zero. We'll update the student at index zero who originally read five books, but now has read eight, so we'll update it with eight. This will completely replace the current value at index zero. Next, we'll update the value at index one. The student at this index had already read three books, and now they've read one more. Instead of replacing the value with four, we'll retrieve the…
Contents
-
-
-
-
What is an array?2m 53s
-
Create a list in Python1m 48s
-
(Locked)
Retrieve data from a list in Python3m 39s
-
(Locked)
Mutate a list in Python2m 45s
-
(Locked)
Solution: Swap items2m 34s
-
(Locked)
Multidimensional lists in Python4m 36s
-
(Locked)
Tuples in Python2m 17s
-
(Locked)
Solution: Square items1m 52s
-
(Locked)
Search array-like structures3m 47s
-
(Locked)
Sort array-like structures3m 27s
-
(Locked)
Solution: Find the second smallest item2m 2s
-
(Locked)
When to use array-like structures1m 38s
-
-
-
-
-
-
-
-