In Python, you can determine whether an element is in a list, using the keyword in and not.
Examples are as follows:
If you need to output the appropriate information, you can use the IF statement, here do not repeat.
------------------------------------------------------------------------------------------Split Line---------------------------- -----------------------------------------------------------------------------------------------------------
Now there is a problem, I have a list of current_users, which is used to store the registered user name. There is also a list of new_users to store the user name that is requesting registration. If the user name of the application is determined to be registered?
The code is as follows:
The result of the operation is:
In the case of the default case, the five names have not been used, it is reasonable.
--------------------------------------------------------------------------------------------------------------- --Split Line--------------------------------------------------------------------------------------------------------------
Now case-sensitive:
The code is as follows:
The list parsing is used here, and a new all-lowercase list is generated, which is then compared. The results of the operation are as follows:
Forrest and Mike are not the same as the names of the existing usernames, but they are rejected for case-insensitive cases. Yes, there's nothing wrong.
PS: It has been previously useful to solve this problem with a dual for loop, but the output is a bit flawed, compared to a simpler list resolution.
Over
How to determine whether an element is in a list without case-insensitive in Python