list.sort(func) speed

mackstann mack at incise.org
Sun Aug 31 15:07:46 EDT 2003


On Sun, Aug 31, 2003 at 02:20:46PM +0200, Peter Otten wrote:
> However, your songs seem to correspond to files, so why not store them in
> your list as (filename, directory) or (filename, fullpath) tuples in the
> first place?

That's a pretty good idea, I think I'll do that.

songs => [("foo.mp3", "/path/to"), ...]

Then the biggest speed hit (splitting the paths and adding the files)
will only happen when adding files, and say, if I add 5 files to the
list, I won't have to suffer the speed hit for ALL of the files, only
those 5, which would be negligable.

> Personally, I would go with a Song class, where the artist, length etc.
> could successively be added, but that would rather be trading speed for
> features...

Yeah, I have thought about it, and it would definitely be the more OOPey
way to go, but I figured that anyone using this with 20,000 files would
get a little grumpy at the speed hit. :)

-- 
m a c k s t a n n  mack @ incise.org  http://incise.org
It was one of those perfect summer days -- the sun was shining, a
breeze was blowing, the birds were singing, and the lawn mower was
broken ...
		-- James Dent





More information about the Python-list mailing list