On Mar 11, 2005, at 2:02 PM, Steven Bethard wrote:
On Fri, 11 Mar 2005 19:48:45 +0100, Alex Martelli <[EMAIL PROTECTED]> wrote:
Which reminds me -- could we have a methodcaller relative to attrgetter
and itemgetter? "Sort a list of strings in a case-insensitive way"
would become *SO* easy with sort(dalist, key=methodcaller('lower'))...
can't REALLY recommend sort(dalist, key=str.lower) then the items of
dalist MIGHT be either str or unicode

I'd like to second this suggestion -- I've run into this problem a few times. When you're using a listcomp or genexp, you can inline it of course, but especially with a lot of functions growing the incredibly convenient key= arguments in 2.5 (e.g. min, max and the deque functions if I recall correctly), methodcaller would be a much more duck-typing friendly way to create such callables.

Yeah, if *only* we had some way to create callables in a nice, short, generic, and easy to understand way.


How about this proposal:
>> sort(dalist, key=lambda x: x.lower())

Who wants to make a PEP for it? Maybe we can add it in Python 3000.

James

_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to