python lists and dictionaries performance

1. List


 

List of operations time complexity
Index -index [] O (1)
Assignment -index assignment O (1)
End plug -append O (1)
Pop -pop () O (1)
Pop -pop (i) O (n)
Insert -insert (i, item) O (n)
Delete -del operator O (n)
Iteration -iteration O (n)
It contains -contains (in) O (n)
Slice -get slice [x: y] O (k)
Delete -del slice O (n)
-Set slice assignment O(n+k)
Reverse -reverse O (n)
Stitching -concatenate O (k)
Sort -sort O(n log n)
Multiplication -multiply O (nk)

2. Dictionary


 

Dictionary operations time complexity
Copy -copy O (n)
Get -get item O (1)
Assignment -set item O (1)
Delete -delete item O (1)
It contains -contains (in) O (1)
Iteration -iteration O (n)

 

Guess you like

Origin www.cnblogs.com/hwnzy/p/10932189.html