How to show a dictionary sorted on a value within its data?

Steven D'Aprano steve+comp.lang.python at pearwood.info
Thu Oct 2 19:16:55 EDT 2014


Dan Stromberg wrote:

> On Thu, Oct 2, 2014 at 12:15 PM, Ian Kelly <ian.g.kelly at gmail.com> wrote:
>> On Thu, Oct 2, 2014 at 10:33 AM,  <cl at isbd.net> wrote:
>>> Ah, so at least there is a reason for it, I'm far from being a
>>> mathematician though so it's not particularly obvious (for me anyway).
>>
>> You're not alone; a lot of people find the terminology not intuitive.
>> Even GvR has publicly lamented the choice of keyword.
> 
> Was lambda almost removed from CPython 3.x?

I'm not sure about "almost", but there was serious discussion about removing
it.


> Anyway, pylint doesn't complain about a bare use of lambda, but it
> does complain about a map applied to a lambda or a filter applied to a
> lambda.  Pylint says they could be replaced by a list comprehension,
> with the warning "deprecated-lambda".

The warning name is misleading, lambda is not deprecated. But stylistically,
many people prefer to use a generator expression in place of map or filter:

# instead of this
map(lambda x: 2*x+1, values)

# use this
(2*x+1 for x in values)

# instead of this
filter(lambda x: x > 23, values)

# use this
(x for x in values if x > 23)



-- 
Steven




More information about the Python-list mailing list