Replace list elements
To replace list elements, you subset the list and assign new values to the subset. You can select single elements or you can change entire list slices at once.
For this and the following exercises, you'll continue working on the areas
list that contains the names and areas of different rooms in a house.
This exercise is part of the course
Introduction to Python
Exercise instructions
- Update the area of the bathroom to be
10.50
square meters instead of9.50
using negative indexing. - Make the
areas
list more trendy! Change"living room"
to"chill zone"
. Don't use negative indexing this time.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Create the areas list
areas = ["hallway", 11.25, "kitchen", 18.0, "living room", 20.0, "bedroom", 10.75, "bathroom", 9.50]
# Correct the bathroom area
# Change "living room" to "chill zone"