Which is fastest dict or list.index() ?
Shagshag13
shagshag13 at yahoo.fr
Sat Jun 1 09:34:42 EDT 2002
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