tjreedy at udel.edu
Sun Aug 31 02:27:19 CEST 2003
"mackstann" <mack at incise.org> wrote in message
news:mailman.1062286079.6474.python-list at python.org...
> I have the following function that compares two filenames based on
> basename only:
> _basenameCmp = lambda self, *pair: cmp(*map(os.path.basename, pair))
> This is so that I can sort a list of files, and the sorting will be
> by filename, ignoring path. There is a minor issue which is not so
> a problem (yet) per se, but just made me curious if there was a
> way to go about this. When calling .sort() on my list, it takes
> complete. Calling .sort(_basenameCmp) on the same list takes 244ms.
> This list could very well be 5 or 10 times the size, in use. Now, I
> believe that my _basenameCmp() needs to be called a lot of times
> can't figure out exactly how many, (len(mylist)/2)^2 ?) and doing a
> string operation that many times is obviously going to slow it down.
> So my question is: Is there anything I could do differently or
> to speed this up?
Google list for decorate sort undecorate pattern
More information about the Python-list