0

Why .lower and .replece didn`t do anything with names? 1st:

names = ["Joey Tribbiani", "Monica Geller", "Chandler Bing", "Phoebe Buffay"]
usernames = []

for name in names:
    name.lower()
    name.replace(' ', '_')
    usernames.append(name)
print(usernames)

2nd:

names = ["Joey Tribbiani", "Monica Geller", "Chandler Bing", "Phoebe Buffay"]
usernames = []

for name in names:
    usernames.append(name.lower().replace((' ', '_')))
print(usernames)

1 Answers1

1

In 1st, you need to "keep the changes" assigning the result to some variable, in your case, the same one:

names = ["Joey Tribbiani", "Monica Geller", "Chandler Bing", "Phoebe Buffay"]
usernames = []

for name in names:
    name = name.lower()
    name = name.replace(' ', '_')
    usernames.append(name)
print(usernames)

In 2nd, you need to provide 2 arguments to replace (the old value and the new one), your tupple is giving just one:

names = ["Joey Tribbiani", "Monica Geller", "Chandler Bing", "Phoebe Buffay"]
usernames = []

for name in names:
    usernames.append(name.lower().replace(' ', '_'))
print(usernames)