I want to see if a new username already exists in a list of users, but for the existing users to also be evaluated user the lower()
function.
I have already tried this:
for nuser in new_users:
if nuser.lower() not in users.lower():
But it does not like the users.lower()
:
I have also tried changing my nuser.lower()
to nuser.title()
, but this is not future proof as I not all users will be writing in title()
format.
My whole code below:
users = ['John', 'Kyle', 'Lily', 'admin', 'Tom']
new_users = ['john', 'Mike', 'TOM', 'Daemon']
if new_users:
for nuser in new_users:
if nuser.lower() not in users.lower():
print("Username: "+nuser+" is available.")
else:
print("Username: "+nuser+" is not available, you will have to choose another.")
For example I expect TOM and Tom to clash and print that the username is not available.
Many thanks!