Back-To-School Deals - hours only!Up to 80% off on all courses and bundles.-Close
Recap
Iterating over a list
Modifying lists
5. Updating list elements – part 1
Working with multiple lists
Congratulations

Instruction

Very well done! In the previous exercises, we only read list elements. Now, we'll talk about techniques to modify list elements.

Mark found out that his sleep duration measurements were inaccurate – he started the timer as soon as he went to bed, forgetting that it takes him 20 minutes to fall asleep. Let's try to modify the list by subtracting 20 minutes from each value in the exercise.

Exercise

Look at the template code. In it, we create a for loop and try to modify the current element. Now, run the template code and see what happens.

As you can see, nothing changed. This is because the duration variable is only a copy of the element's value. This means that whatever we do with duration inside the loop won't have any impact on the actual list element.