tjreedy at udel.edu
Fri Jan 23 19:22:44 CET 2004
> Well I too sometimes need the keys in a dictionary to be sorted and your
> solutions wouldn't help. The problem is the following.
> I have a number of key value pairs, like names and telephone numbers.
> Just more subject to change. Now I want the telephone numbers of
> whose name starts with "jan".
> Or I just inserted a name and want to know who is alphabetically next.
> Or I want to know who is first or last.
A python dict is not very well suited to this, especially for large numbers
of key,value pairs. However, if you do pull out sorted lists of keys, use
the bisect module to find specific keys. log(n) behavior is fine.
A table with a btree index is designed for the things your want to do.
There is a btree,py in zope (by Tim Peters, I believe), but I do not know
how 'extractable' it is. You could search the archives.
Terry J. Reedy
More information about the Python-list