Which is fastest dict or list.index() ?

Raymond Hettinger python at rcn.com
Sat Jun 1 20:06:01 EDT 2002


There are a lot of ways to implement an OrderedDictionary.
Take a look at
http://home.arcor.de/wolfgang.grafen/Python/Modules/Modules.html
and http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/107747
If you want a skiplist version, let me know and I'll send it.

Raymond Hettinger


"Shagshag13" <shagshag13 at yahoo.fr> wrote in message
news:adaih2$vtb8c$1 at ID-146704.news.dfncis.de...
> I need a structure to hold a correspondence between toons and id like
>
> {'Bugs' : 0, 'Mickey' : 1, 'Babs' : 2, 'Jerry' : 3, 'Tom' : 4, 'Babs' : 5}
>
> I must be able to alpha sort these toons (without loosing their id), and
> access a toon from an id or an id from a toon.
>
> By now a use a dict and a list : the dict gives index from a toon, and the
> list gives me a toon from an index.
>
> {'Bugs' : 0, 'Mickey' : 1, 'Babs' : 2, 'Jerry' : 3, 'Tom : 4, 'Babs' : 5}
> ['Bugs', 'Mickey', 'Babs', 'Jerry', 'Tom', 'Babs']
>
> (the id is used somewhere else a key to a collection of elements)
>
> My question is which is the best way (best = quickest and memory safe) to
> handle this ?
> Should i subclasse from dict or list ?
> Should i consider using only one list with toons (and use their index as
id)
> ?
> Should i use 2 dicts ?
>
> Many thanks to you for helping
>
> s13.
>
>
>





More information about the Python-list mailing list