Given that we have comprehensions that use s simple expression, and operator.itemgetter for common keys, the use cases for these simple lambdas are pretty rare these days. Sure, some folks seem to prefer map and filter as a matter of style, but I don’t think we need to create cryptic notation to make that easier, NOTE: I expect many of the examples you found in the stdlib predate comprehensions and itemgetter. -CHB On Wed, Sep 29, 2021 at 8:09 AM Steven D'Aprano <steve@pearwood.info> wrote:
On Wed, Sep 29, 2021 at 09:11:35AM -0000, Dominik Vilsmeier wrote:
* `sorted(items, key=?['key'])` * `filter(? > 0, items)` * `map(f'{?:.3f}', items)`
I think those are massively more cryptic and hard to read than an explicit lambda. Being too terse is worse that being too verbose: consider how few people use APL compared to how many use Java.
"lambda" is admittedly an odd name for a concept, most familiar to computer science theorists, but at least it is pronouncable in English. We can read it and talk about it:
"Pass a lambda as the key parameter."
Whereas here how do we pronounce "?"? "Pass a question mark as the key parameter" sounds like *all you need do* is pass the literal ? symbol. In practice people are going to call it lambda, in which case you might as well just write lambda.
And please take mercy on the poor beginners who have to Google for "Python ?" to try to work out what on earth this does. At least other punctuation marks are either well known from school maths or other languages.
_______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-leave@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/A5JTJY... Code of Conduct: http://python.org/psf/codeofconduct/
-- Christopher Barker, PhD (Chris) Python Language Consulting - Teaching - Scientific Software Development - Desktop GUI and Web Development - wxPython, numpy, scipy, Cython