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 â)
2 Answers
+ 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.