0

How do I check make sure I don’t have duplicates. (Python)

Im trying to figure out where/how do I compare my two variables in lower() to make sure any variations of a username are rejected. My code is: current_users = [‘Denis’, ‘Liz’, ‘Jim] new_users=[‘denis’, ‘Tom’, ‘Sara’, ‘JIM] for new_users in new_users: if new_users in current_users: print( “username {new_users} is unavailable”) else: print(“ {new_users} is available “)

29th Mar 2020, 3:57 PM
Paul Muyu
Paul Muyu - avatar
2 Respuestas
+ 3
This is the correct code: current_users = ['Denis', 'Liz', 'Jim'] new_users = ['denis', 'Tom', 'Sara', 'JIM'] #converting usernames to lowercase. current_users = [x.lower() for x in current_users] new_users = [x.lower() for x in new_users] for new_users in new_users: if new_users in current_users: print( f"{new_users} is unavailable") else: print(f"{new_users} is available") #there might be shorter and better way of doing this.
29th Mar 2020, 4:57 PM
Bibek Oli
Bibek Oli - avatar