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.