I have the following python code:
def make_great(l):
l = ['The great ' + magician for magician in l]
magicians = ['Tom']
make_great(magicians)
print(magicians)
The print statement prints the original list, not the one modified by the make_great()
function. I was trying to figure out a way of modifying each element of a python list without explicitly accessing it's index and then reassigning that index a new value. Wouldn't the magicians
list now point to the new list formed by the comprehension based on Python's memory model ? I am guessing that I am not getting the desired results because this is a scoping issue ? But when I pass in magicians
, it replaces l
in the function argument so the python interpreter actually sees magicians = ['The ...
?