List comprehension vs generator expression's weird timeit results?
问题 I was answering this question, I preferred generator expression here and used this, which I thought would be faster as generator doesn\'t need to create the whole list first: >>> lis=[[\'a\',\'b\',\'c\'],[\'d\',\'e\',\'f\']] >>> \'d\' in (y for x in lis for y in x) True And Levon used list comprehension in his solution, >>> lis = [[\'a\',\'b\',\'c\'],[\'d\',\'e\',\'f\']] >>> \'d\' in [j for i in mylist for j in i] True But when I did the timeit results for these LC was faster than generator: