-1

I'm learning some python in these days so I'm a beginner, I have a list with "current_users", and a list with "new_users", I want that no usernames must be repeated, so if a username (ex. John) is both in current_users and new_users, the program prints "Change your username", however the problem is that if new_users has "John" and current_users "JOHN", the program doesn't print that string since it considers them 2 different usernames, I've already tried to lower the names in new_users using .lower(), but I don't know how to do the same with current ones

current_users = ["Carlo", "carla", "FRANCESCO", "giacomo"]
new_users = ["carlo", "Francesco", "luca", "gabriele"]


for new in new_users:
    if new.lower() in current_users:
        print("Change your username")
    else:
        print("Welcome!")

I expect the program to output "Change your username" for each name that has already been used

  • As this was marked a duplicate, please see that question for how to convert `current_users` to a list of lower case names. Then you will be able to compare lower to lower. – krethika Apr 12 '19 at 18:07
  • Better to only accept lowercase usernames in the first place, but that's beside the point. – wjandrea Apr 12 '19 at 18:07

1 Answers1

1

You need to cast to lower both the new usernames and the current users.

current_users = ["Carlo", "carla", "FRANCESCO", "giacomo"]
new_users = ["carlo", "Francesco", "luca", "gabriele"]


for new in new_users:
    if new.lower() in [current.lower() for current in current_users]:
        print("Change your username")
    else:
        print("Welcome!")
DobromirM
  • 2,017
  • 2
  • 20
  • 29