Need help with Thread Shed project


#1

project link (https://www.codecademy.com/paths/computer-science/tracks/cspath-python-objects/modules/cspath-python-strings/projects/thread-shed)

Here is the code:


I have a question about steps 8 and 9 of this project
In the code it is from line 120 to line 129 (i commented around that)

It works, but somehow, i dont understand, what is happening in the inner cycle.
Is it replacing string[i] with string[i].strip?


#2

yes, you are updating element in the string list with the stripped version.


#3

At first, i thought that i couldn’t do that because it would change the string
Soo, we basically put new element into the place of the old one?


#4

if we look at the documentation:

https://docs.python.org/2/library/string.html#string.strip

wee see strip returns a copy of the string.

Lists on the other hand are mutable, so we do update the list (replacing old by new)


#5

Thank you for clarification! :slight_smile:


#6

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.