[Tutor] fast list traversal

wesley chun wescpy at gmail.com
Thu Oct 30 23:06:12 CET 2008


based on the all the performance questions, i would say agree that
dictionary access is faster than lists (hashes exist cuz they're fast)
but they use up more memory, as shown in shawn's numbers. also, one of
the reasons why slots was added to classes was because the attribute
dictionary began to impact memory (when creating many instances), so
converting that to __slots__ list of attributes instead made it more
conservative of resources.

thus, i would suggest using sets instead. if the data doesn't change,
then frozensets. a for-loop thru sets would be very fast; and in
Python 3.0, you can use *set comprehensions* too. :-)

shawn, do you have time to run some numbers for sets and frozensets?

anyway, just a suggestion...
-wesley

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
"Core Python Programming", Prentice Hall, (c)2007,2001
    http://corepython.com

"Python Web Development with Django", Addison Wesley, (c) 2008
http://withdjango.com

wesley.j.chun :: wescpy-at-gmail.com
python training and technical consulting
cyberweb.consulting : silicon valley, ca
http://cyberwebconsulting.com


More information about the Tutor mailing list