1

I want to add a phrase "the Great" before every name in list names, why this did not work?

def make_great(names):
    great_magicians = []
    for name in names:
        great_magicians.append("the Great " + name)
    names = great_magicians

Submitted September 14th 2021 by Admin

Answers
0

The function call should return the values

def make_great(names): great_magicians = [] for name in names: great_magicians.append("the Great " + name) return great_magicians names = make_great(['A', 'B'])
print(names)

output

['the Great A', 'the Great B']

Admin | 1 month ago


0

names is a local reference to the list. you are setting it locally but the reference to your object is lost when the function gets out of scope.

I suggest you return great_magicians.

def make_great(names): great_magicians = [] for name in names: great_magicians.append("the Great " + name) return great_magicians

Admin | 1 month ago


0

Try this:

['The Great ' + name for name in names ]

Admin | 1 month ago



Relevant Questions