What Can A 'TreeDict' (Or Treemap) Be Used For In Practice?

Posted by Seun Osewa on Stack Overflow See other posts from Stack Overflow or by Seun Osewa
Published on 2009-06-18T17:59:25Z Indexed on 2010/04/10 11:23 UTC
Read the original article Hit count: 205

Filed under:
|
|
|
|

I'm developing a 'TreeDict' class in Python. This is a basically a dict that allows you to retrieve its key-value pairs in sorted order, just like the Treemap collection class in Java.

I've implemented some functionality based on the way unique indexes in relational databases can be used, e.g. functions to let you retrieve values corresponding to a range of keys, keys greater than, less than or equal to a particular value in sorted order, strings or tuples that have a specific prefix in sorted order, etc.

Unfortunately, I can't think of any real life problem that will require a class like this. I suspect that the reason we don't have sorted dicts in Python is that in practice they aren't required often enough to be worth it, but I want to be proved wrong.

Can you think of any specific applications of a 'TreeDict'? Any real life problem that would be best solved by this data structure? I just want to know for sure whether this is worth it.

© Stack Overflow or respective owner

Related posts about collections

Related posts about dict