I have a dict such as:
d=dict()
d[('1','2')] = 'value'
Then I query the key :
if (k1,k2) in d.keys():
When there is million records,the speed is a suffering, any problem with the 'in' operator?
Is it sequential search?
I have to concat str as key to bypass this issue.
You should use
(k1,k2) in d
instead of calling d.keys()
.
Doing it your way, in Python 2 will result in a linear search and rather negates the benefits of a dict
. In Python 3 your code is efficient (see comments below) but my version is clearer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With