Is there a structure in Python which supports similar operations to C++ STL map and complexity of operations correspond to C++ STL map?
Is there a structure in Python which supports similar operations to C++ STL map
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
dictis usually close enough – what do you want that it doesn’t do?If the answer is “provide order”, then what’s actually wrong with
for k in sorted(d.keys())? Uses too much memory, maybe? If you’re doing lots of ordered traversals interspersed with inserts then OK, point taken, you really do want a tree.dictis actually a hash table rather than a b-tree. But thenmapisn’t defined to be a b-tree, so it doesn’t let you do things like detaching sub-trees as a newmap, it just has the same performance complexities. All that’s really left to worry about is what happens todictwhen there are large numbers of hash collisions, but it must be pretty rare to use Python in situations where you want tight worst-case performance guarantees.