Python has built in some very interesting but very useful functions, fully embodies the language charm of Python!filter (function, sequence): Executes function (item) on item in sequence, and the item that executes the result of true is composed of a list/string/ The Tuple (depending on the type of sequence) returns:>>> def f (x): return x% 2! = 0 and x% 3! = 0>>> filter (F, Range (2, 25))[5, 7, 11, 13, 17,
can master after you finish your study1, master the basic Linux system operation;2, Master Python basic programming grammar;3, the establishment of programming thinking and object-oriented thinking;Practical problems that can be solved:String sorting, cutting, inverse; guessing numbers, airplanes vs games;Market value:Have programming thinking, Master Python basic grammar, can develop some small gamesThe k
Several important python functions (lambda, filter, reduce, map, zip) and pythonlambda
1. Anonymous function lambda
Lambda argument1, argument2,... argumentN: expression using arguments
1. lambda is an expression rather than a statement.
Because of this, lambda can appear where def is not allowed in python syntax-for example, in a list constant or in a function
Python has many functional programming methods. This article describes the most common functions.Note: This article is based on python2.7. different versions may cause differences.Zip-fundingStandard format zip (seq [, seq [, seq])Example:A = (I for I in range (3 ))B = [4, 5, 6]C = (7, 8, 9)Abc = zip (a, B, c)The result of abc is [(0, 4, 7), (1, 5, 8), (2, 6, 9)]Therefore, the role of the zip function is already very obvious. It is like raising funds
Using Python to do data processing analysis often uses the list as a built-in object, there are usually some calculations on the list, such as filtering, element lookup, and so on, for loops traversal does not have a big impact on performance when the data is small, but the bottleneck occurs when the data volume is large. But luckily Python provides several built-in global functions to efficiently handle li
=123 ;A variable in Python can also point to a method (function, as you call it to understand it).Take the Max method here as an exampleprint(‘最大值函数 :‘max([12310020100Returns the maximum value of 100, then we point the function to an object trymax;print(‘对象指向函数 最大值为:‘, maxValue(102020So since the function can point to a variable, then the function can be passed as a parameter to another function? (guess) Let's try it!This time, we'll experiment with
standard library section has completed the writing of strings, data types, mathematical operations, files and directories, data storage, process communication, program framework, and some parts of the operating system , data compression, format parsing, data encryption, network programming, development tools, runtime Environment, Several parts of the language service have not yet been written.The extension library includes fabric and pexpect.The appendices include CPython, IPython, PDB, Pip, an
1. DescriptionThe map function in Python is applied to each iteration of an item and returns a list of results. If other iterative parameters are passed in, the map function iterates through each parameter with the corresponding processing function. The map () function receives two parameters, one is a function, the ot
Python learns Day 5 high-level functions map/reduce filter sorter return functions anonymous function decorators partial functions, pythonsorter
Higher-orderfunction
Variable can point to function
>>> Abs # abs (-10) is a function call, while abs is the function itself.
>>> F = abs # the function itself can also assign values to variables.
>>> F # variables can point to functions.
>>> F (-10) # variable
① in terms of parameters:Map () Function:Map () contains two parameters, the first one is a function, the second is a sequence (list or tuple). where a function (that is, a function of the first parameter position of a map) can receive one or more parameters .Reduce () function:The first parameter of reduce () is a function, and the second is a sequence (list or tuple). However, its function must receive two parameters .② from the numerical effect on
)For example, to sum a sequence, it can be implemented with reduce:def Add (x, y ): return x+y for in range (1,101)])Of course, the sum operation can be built directly into the Python function sum (), no need to use reduce.But if you convert the sequence [1,3,5,7,9] into an integer 13579,reduce it will come in handy:def f (x, y ): return x*10+yforif x%2!=0])13579This example is not very useful in itself, but if you consider that the string str i
This article describes the basic python Tutorial-related information on Map usage. A simple example is provided here. For more information, see
Python Map
Map maps a function to all elements in an input list. Map specifications:
This article to you to share is the detailed description of the Python function map,filter,reduce, the content is very good, hope to help the needy friends
1.map
MapA function is mapped to all elements of an input list. This is its specification:
Specification
Map (function_to_apply, list_of_inputs)
Most of the time,
Python has several built-in functions that are interesting: map/filter/reduce, it's all about a collection, filter is easy to understand for filtering, map is used for mapping, and reduce is used for merging. Is the three carriage of the Python list method.
Filter () function:The function of the filter function i
filter, map, and reduce are all processed on a set, filter is easy to understand for filtering, map is used for mapping, and reduce is used for merging. Is the Python list method of three carriages.1. The function of the filter function corresponds to the filter.the definition of the filter function:Filter (function or None, sequence), list, tuple, or stringfunct
# This is a learning note for the Liaoche teacher Python tutorial1 , Map functionmap () The function receives two parameters, one is the function, and the other is the ITERABLE,MAP functions the incoming function to each element of the sequence, and takes the result as a new Iterator return# For example, there is a function f (x) =x2, to function in a list [1, 2,
ArticleDirectory
1. Lambda ()
2. Filter ()
3. Map ()
4. Reduce ()
5. Comprehensive examples
1. Lambda ()
Lambda () is an anonymous function in Python. Its syntax is as follows:
Lambda [arg1 [, arg2,... argn]: Expression
The following is an example of 1 + 2 = 3.
>>> Fun = Lambda X, Y: x + y >>> fun (1, 2) 3
>>> (Lambda X, Y: X + Y) (1, 2) 3
2. Filter ()
Filter (
Multiprocessing is a multi-process library for Python, and Multiprocessing.dummy is a multi-threaded version that uses the same.There is a pool concept, and the process pool/thread pool has a common approach, in which the methods are compared as follows:There is four choices to mapping jobs to process. Here is the differences: Multi-args Concurrence Blocking Ordered-resultsmap no yes yes yesa
Usemap()function, the user entered an irregular English name, into the first letter uppercase, other lowercase canonical name. For example, enter:[‘adam‘, ‘LISA‘, ‘barT‘], Output:[‘Adam‘, ‘Lisa‘, ‘Bart‘]. Code:#定义一个listL = [] #设置名字的个数n = Int (raw_input ("Please enter the number of the name:")) #利用循环将名字追加到list里面for num in range (n): names = Raw_input ("Please enter the name:") l.append (names) #定义函数, First Capital def format_name (name) return Name[0].upper () + Name[1:].lower () #利用
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.