0

I am interested in knowing how the keys of a dictionary would be searched if we wanted to check that a value 'x' would be a key in the dictionary. I understand that this would be done by doing something like this

if x in dictionary:
    print 'yes'

How does Python search through the dictionary to find the key 'x'? Does it go element by element? Or does it simply check if an exception/error is thrown if indexing the dictionary by 'x'? What would be the complexity?

  • [Dictionary Keys](https://wiki.python.org/moin/DictionaryKeys) – MrAlexBailey Feb 10 '17 at 13:40
  • Related: [What is the true difference between a dictionary and a hash table?](http://stackoverflow.com/questions/2061222/what-is-the-true-difference-between-a-dictionary-and-a-hash-table) – blacksite Feb 10 '17 at 13:41

0 Answers0