Raymond Hettinger wrote:
> Azolex:
>> Let's push the diagnosis a bit further : the aversion to the keyword
>> "lambda" has to do with the fact that it ignores the english word used
>> by all non-geeks to convey the meaning, eg "given"
>
> Right. However, Guido has said that lambda is here to stay
[Noah]
> I suggested the above because it wasn't obvious to me how one would
> pass the arbitrary set of attributes to the lambda expression (and I
> envisioned them being specified as strings in this case, since the set
> of attributes will be coming from a web form).
>
> So what about the followi
Azolex:
> Let's push the diagnosis a bit further : the aversion to the keyword
> "lambda" has to do with the fact that it ignores the english word used
> by all non-geeks to convey the meaning, eg "given"
Right. However, Guido has said that lambda is here to stay,
so it's time to get over it.
R
Raymond Hettinger wrote:
>
> The cult of lambda avoidance has lost contact with reality. [...]
> Lambda avoidance is rooted in two things, an aversion to the keyword
> name [...]
Let's push the diagnosis a bit further : the aversion to the keyword
"lambda" has to do with the fact that it ignore
I'm sure my avoidance of lambdas as due as much to laziness as
adherence to principle. This is a good opportunity to learn about them.
I suggested the above because it wasn't obvious to me how one would
pass the arbitrary set of attributes to the lambda expression (and I
envisioned them being spe
Kent Johnson wrote:
> Scott David Daniels wrote:
>> Kent Johnson wrote:
>>> In Python 2.5 you can do this with operator.attrgetter():
>>> L.sort(key=operator.attrgetter('whatever', 'someother', 'anotherkey'))
>>
>> Note: this is also available in Python 2.4
>
> No, the ability to specify more th
[George Young]
>> For multiple keys the form is quite analogous:
>>
>> L.sort(key=lambda i: (i.whatever, i.someother, i.anotherkey))
[Noah]
> If you are lambda-phobic (as I am) this should also work for an
> arbitrary set of attributes:
>
> attrs = 'attr1 attr2 attr3'.split()
> sortlist = [[getat
Scott David Daniels wrote:
> Kent Johnson wrote:
>> In Python 2.5 you can do this with operator.attrgetter():
>> L.sort(key=operator.attrgetter('whatever', 'someother', 'anotherkey'))
>
> Note: this is also available in Python 2.4
No, the ability to specify more than one attribute name, making
Kent Johnson wrote:
> In Python 2.5 you can do this with operator.attrgetter():
> L.sort(key=operator.attrgetter('whatever', 'someother', 'anotherkey'))
Note: this is also available in Python 2.4
--Scott David Daniels
[EMAIL PROTECTED]
--
http://mail.python.org/mailman/listinfo/python-list
gry@ll.mit.edu wrote:
> For multiple keys the form is quite analogous:
>
>L.sort(key=lambda i: (i.whatever, i.someother, i.anotherkey))
>
> I.e., just return a tuple with the keys in order from your lambda.
> Such tuples sort nicely.
In Python 2.5 you can do this with operator.attrgetter()
If you are lambda-phobic (as I am) this should also work for an
arbitrary set of attributes:
attrs = 'attr1 attr2 attr3'.split()
sortlist = [[getattr(o,a) for a in attrs] + [o] for o in objects]
sorted_objects = [x[-1] for x in sorted(sortlist)]
-Noah
--
http://mail.python.org/mailman/listinfo/
For multiple keys the form is quite analogous:
L.sort(key=lambda i: (i.whatever, i.someother, i.anotherkey))
I.e., just return a tuple with the keys in order from your lambda.
Such tuples sort nicely.
-- George Young
--
http://mail.python.org/mailman/listinfo/python-list
12 matches
Mail list logo