in need of some sorting help
Scott David Daniels
scott.daniels at acm.org
Fri Mar 3 12:31:41 EST 2006
ianaré wrote:
> ....
> files.sort(key=lambda x: x.lower())
> files.sort(key=lambda x: os.path.dirname(x))
This is exactly why some of us hate lambda. It encourages
long-way-around thinking.
files.sort(key=lambda x: os.path.dirname(x))
is better written as:
files.sort(key=os.path.dirname)
Learn to have your skin itch when you see:
... lambda name:<expr>(name)
And yes, I concede that it _is_ useful in your .lower expression.
It's not that lambda is bad, rather that it seems to encourages
this 'lambda x:f(x)' stuff.
--Scott David Daniels
scott.daniels at acm.org
More information about the Python-list
mailing list