Usage analysis of map, any, all functions in Python

Source: Internet
Author: User
Tags lowercase

This article mainly introduces the use of map, any and all functions in Python, examples analyze the related usage techniques of map, any and all functions, which have some reference value, and need friends can refer to

This example describes the use of map, any, all functions in Python. Share to everyone for your reference. The specific analysis is as follows:

Recently want to learn Python, has been more concerned about Python, yesterday in the Python bar to see a post asked how in Python how to determine whether the password is compliant, there are a lot of replies in the loop, in addition to another does not use the loop, the code is very concise, the following is code:


1 2 3 4 5 6 def volid (pwd): a = any (map (str.isupper,pwd)) b = No (map (str.islower,pwd)) C = Any (map (str.isdigit,pwd)) d = no All (map) ( STR.ISALNUM,PWD)) return to All ([A,b,c,d])

The isupper islower isdigit isalnum function is very well understood, that is, whether it's uppercase, lowercase, numbers, all numbers and letters (in turn, there are no other symbols), and the map function here is to execute each element of the next set with the function of the first parameter, returns a set of bool types, the outermost any and all functions are easier to understand, and can be understood with "or" and "and" if a parameter collection is true, The any function returns True, which is equivalent to all the elements "or", only if the parameter set is all true, the all function returns True, and all other cases return false, so if the Volid function passes in a string containing uppercase and lowercase letters and special symbols, ABCD is assigned true, and the last return is true, so this function can tell if the password is complex enough.

Leave a question for yourself, if you require only two items in the four items, the function of how to write more concise. Interested friends can practice.

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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: and provide relevant evidence. A staff member will contact you within 5 working days.