-2

Possible Duplicate:
How are Python’s Built In Dictionaries Implemented

I am fairly new to python and have a background in java. I was wondering whether the dictionary in python has the same search complexity as for hash maps in java. Example: searching for a key in a hash table/map in java is a constant time operation, I was wondering whether searching for a key in a dictionary in python is also a constant time operation. I have read through a few pages of python documentation regarding mapping but it doesn't seem to indicate any hashing of keys of dictionary in python so I was wondering whether:

  1. searching keys in a dictionary in python was constant time operation.
  2. If so how do they achieve this constant time search without hashing?
Community
  • 1
  • 1
anonuser0428
  • 11,789
  • 22
  • 63
  • 86

1 Answers1

2

Python dictionaries have O(1) search complexity.

See the Time complexity wiki page.

Python dictionaries are implemented as a hash table, and keys are hashed; you can influence the hashing by implementing a __hash__ method.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343