List comprehension is a very interesting function, it should be a syntax sugar bar, the name of the list deduction is probably a free translation, but list comprehension this really do not know how to translate.
List derivation is an example of Python's support for functional programming concepts.
The function of the list deduction is to reduce the amount of code written, you can save things, it would have been two lines, now only need one line.
For example, to do the same with all the data in a list, you can usually write this:
data=[1,2,3,4,5,6]result=[] for in data: result.append (item* Item)print(result) [1, 4, 9, 16, 25, 36]
Above, you need to define the data type of result, then process each value in data with a for loop, then assign the value to result,
However, when you have a list derivation tool, you can reduce the amount of code:
data=[1,2,3,4,5,6]result for in data]print(result) [1, 4, 9, 16 , 25, 36]
The Item*item part, which can be either an expression or a method
Head Frist Python Reading notes list deduction (list comprehension)