[Tutor] fast list traversal

Dinesh B Vadhia dineshbvadhia at hotmail.com
Fri Oct 31 00:40:36 CET 2008


Thanks Wesley

I use both dictionaries (especially defaultdict) and sets all the time but for this particular problem I need the dictionary or set (preferably) to be ordered ie. the set contains integers, which don't change, but they have to be ordered - low to high - when read back with a for-loop.

Btw, cannot move to Python 2.6 or 3.0 until Numpy/Scipy catches up.

Dinesh



From: wesley chun 
Sent: Thursday, October 30, 2008 3:06 PM
To: Dinesh B Vadhia 
Cc: tutor at python.org 
Subject: Re: [Tutor] fast list traversal


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081030/9402292b/attachment.htm>


More information about the Tutor mailing list