Is there anything faster than a dictionary?

I cant n-grams and build a dictionary to store n-gram values. I have something like this:

{ "it is" : 0.01, "this is" : 0.005, "hello i" : 0.2 "hello you" : 0.3 ... } 

There are 3 million keys in my dictionary, and it takes 0.0002(s) to get the bigramvalue value.

Is there anything faster than a dict that I could use?

+5
source share
1 answer

No, I don’t think there is anything faster than a dict . The difficulty of checking its index is O(1) .

 ------------------------------------------------------- Operation | Average Case | Amortized Worst Case | ------------------------------------------------------- Copy[2] | O(n) | O(n) | Get Item | O(1) | O(n) | Set Item[1] | O(1) | O(n) | Delete Item | O(1) | O(n) | Iteration[2] | O(n) | O(n) | ------------------------------------------------------- 

PS https://wiki.python.org/moin/TimeComplexity

+6
source

Source: https://habr.com/ru/post/1273716/


All Articles