Fast attribute/list item extraction
ramen at lackingtalent.com
Tue Dec 2 07:42:50 CET 2003
In article <bqfq8k$qb$0 at 220.127.116.11>, Bengt Richter wrote:
> On Mon, 01 Dec 2003 10:11:16 GMT, "Raymond Hettinger" <vze4rx4y at verizon.net> wrote:
>>> > extract
>>> > extract["key"]
>>> I'm having a hard time seeing the use cases, given that I find
>>> most of them more readable if done with list comprehensions
>>> or good ol' for loops.
>>Peter's post focused on implementation instead of the context.
>>For Py2.4, the list.sort() will have an optional key argument that encapsulates
>>the decorate/sort/undercorate pattern. For example, here is the new fastest way
>>to have a case insensitive sort leaving the original case intact:
>>>>> words = 'The quick BROWN fox JumPed OVER the LAzy dog'.split()
> Please can we have a name that better expresses the functionality?
> E.g., 'keyfunc', or 'xform' or something that says the method is expecting
> a function that will be called with the sorting argument to produce the value
> used in sorting? "key=" doesn't do it IMO.
I agree. To me, the word "key" has deep meaning with respect to hash tables
and databases, and reading it as a parameter makes me first think it might
require a string or integer. I would prefer something like "sortfunc" or
"decorator", but both of your suggestions would be fine by me and preferable
.:[ dave benjamin (ramenboy) -:- www.ramenfest.com -:- www.3dex.com ]:.
: d r i n k i n g l i f e o u t o f t h e c o n t a i n e r :
More information about the Python-list