Quick question to mainly satisfy my curiosity on the topic.
I am writing some large python programs with an SQlite database backend and will be dealing with a large number of records in the future, so I need to optimize as much as I can.
For a few functions, I am searching through keys in a dictionary. I have been using the "in" keyword for prototyping and was planning on going back and optimizing those searches later as I know the "in" keyword is generally O(n) (as this just translates to python iterating over an entire list and comparing each element). But, as a python dict is basically just a hash map, is the python interpreter smart enough to interpret:
if(key in dict.keys()):
...code...
to:
if(dict[key] != None):
...code...
It is basically the same operation but the top would be O(n) and the bottom would be O(1).
It's easy for me to use the bottom version in my code, but then I was just curious and thought I would ask.