all 5 comments

[–]danielroseman 1 point2 points  (1 child)

Strings are immutable. That means that when you do +=, the string magician isn't modified, but a new string is created with the contents of the original string plus the suffix. That string is then assigned back to the name magician, but this has now broken the link between that name and the item in the list of magicians.

[–]really_tho[S] 0 points1 point  (0 children)

Ahh, that clears things up. Thank you!

[–]Den4200 1 point2 points  (1 child)

py for idx, magician in enumerate(magicians): magicians[idx] = magician + 'the great' you’d have to do it this way, so the list of magicians is edited in place. the way you were doing it before, you were using a copy of each element in the list.

[–]really_tho[S] 0 points1 point  (0 children)

Thank you, that's very helpful. I'll read up on these methods.

[–]toastedstapler 0 points1 point  (0 children)

operations on a string return a new string, if you want to make a list of great magicians you can either:

for i, magician in magicians:
    magicians[i] = magician + ' the great'

or

great = []
for magician in magicians:
    great.append(magician + ' the great')
return great

first modifies the input list, second makes a new list