Why is itertools.chain faster than a flattening list comprehension?
问题 In the context of a discussion in the comments of this question it was mentioned that while concatenating a sequence of strings simply takes ''.join([str1, str2, ...]) , concatenating a sequence of lists would be something like list(itertools.chain(lst1, lst2, ...)) , although you can also use a list comprehension like [x for y in [lst1, lst2, ...] for x in y] . What surprised me is that the first method is consistently faster than the second: import random import itertools random.seed(100)