List concatenation: speed : List Cancatenation « List « Python






List concatenation: speed

List concatenation: speed
 
L = [1, 2]
L = L + [3]            # concatenate: slower
print L

L.append(4)            # faster, but in-place
print L

L = L + [5, 6]         # concatenate: slower
print L

L.extend([7, 8])       # faster, but in-place
print L

L += [9, 10]       # mapped to L.extend([9, 10])
print L


           
         
  








Related examples in the same category

1.Using List OperatorsUsing List Operators
2.Concatenation ( + )
3.Concatinate two listsConcatinate two lists
4.List concatenation DemoList concatenation Demo