Seven, generator expression and list resolution differences
Builder expression:
Format: (expr for ITER in iterable [if condition])
The generator is the result of an iteration, not an expression evaluated immediately
Gets a generator object, not a list
Cannot use index, append, etc. list operations
can be converted to list object using the list () factory method
difference between builder and column expressions :
The outermost layer of the builder format is one (), while the outermost list parsing format is a []
The generator is to not read the data once, and the list resolution is to read all the data (memory-consuming)
The generator Returns a generator object (not directly looping), and list resolution returns a new list
------------------------------------------------------
#引入时间工具
Import time
f = open ("E:/pythondata/ods_hbv_addattention")
Start1=time.clock ()
Lines1 = [T.split ("") for T in F]
End1=time.clock ()
Print End1-start1
Print type (lines1)
#文件越大体现越明显
Start2 = Time.clock ()
Lines2 = (T.split (",") for T in F)
End2 = Time.clock ()
Print End2-start2
Print type (lines2)
--------------------------------------------------------------