How to determine whether an element is in a list without case-insensitive in Python

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.