+=
can only be used to expand one list with another list , and extend
can be used to expand one list with an iterative object
eg.
You can do
a = [1,2,3] a.extend(set([4,5,6]))
but you cannot do
a = [1,2,3] a += set([4,5,6])
For the second question
[item for sublist in l for item in sublist] is faster.
see Creating a flat list from a list of lists in Python
qiao
source share