Efficient searching through objects

bearophileHUGS at lycos.com bearophileHUGS at lycos.com
Thu Feb 26 07:21:17 EST 2009


sert:
> I have implemented this by creating a list with all the people's
> names and another list with their objects (their data).
>
> It works but after profiling the code it turns out that half the
> time spent in the program is spent in the list.index() function
> looking up names. Isn't there a less goofy and more efficient
> way of doing this?

Try using a dict instead, where keys are the names and objects the
values (it turns a linear search in a quick hash look up). . Then tell
us the performance changes.

Bye,
bearophile



More information about the Python-list mailing list