0

For some reason the make_great function is not affecting the output of the show_magicians function. I'm trying to alter the list but it's not working.

# the make_great function is not affecting the show_magicians function as 
# intended

magicians = ['david', 'caroline', 'benjamin', 'alex', 'steve']

def make_great(magicians_to_change):
    for magician in magicians_to_change:
        magician = "the Great " + magician

def show_magicians(magicians_to_print):
    for magician in magicians_to_print:
        print(magician.title())
    print("\n")

show_magicians(magicians)
make_great(magicians)
show_magicians(magicians)

I'm aware this is a stupid newb question, so thanks in advance for dealing with it.

Edited by Talruk: edited out stupid mistake

2
Contributors
1
Reply
20
Views
3 Weeks
Discussion Span
Last Post by rproffitt
0

Read your code, Now look at what you did there. You never altered the magicians list (or array.)

You use for magician in magicians_to_change: so you get a copy back of the element and not the array item itself. Then you change your copy then never use it.

Next time just use the old school index method. Example. You fix if borked.

for index, item in enumerate(magicians):
    magicians[index] = "Bullwinkle and " magicians[index]

Edited by rproffitt: Clarifying

Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.