Abdulla Al Kathiri writes: > How is this not pythonic? > > series.apply(x -> x**2) > Compared to.. > series.apply(lambda x: x**2)
The main problem is that the second already exists, and the first doesn't, while the first adds no new power to the language, and isn't enough more readable (and some would argue less readable, expecially in the multiple "lots of irritating parentheses" form) than the "lambda" version. While it's not a good idea to take the Zen too seriously, "There should be one-- and preferably only one --obvious way to do it." is often good advice. "Although that way may not be obvious at first unless you're Dutch." means that often that way must be taught to most developers, with "lambda" being an extreme case since very few of us come from the Lisp, Haskell, or Mathematical Logic worlds any more, so references to lambda are infrequent. A small issue is that with a different value, "f(x -> V)" is also possibly a typo for "f(x) -> V", and likely to occur if you have automagic parenthesis matching in your editor. In general, Python's designers prefer (and try to encourage) a style emphasizing building up complex applications from relatively small *named* functions, rather than large monolithic blocks of code. Random's cavil about warty keywords notwithstanding, I kinda like my idea of using a "def expression" to pass a local function as a keyword argument. I wouldn't be surprised if Guido pops up to say "I thought of that in 1998, but it was too cute by half", though. :-) One could argue that this fits the typical human brain well, with its ability to handle chunked data in groups of 7 +/- 2 items. It's unarguable that Python has become very popular, and that its fans are quite devoted to it. Something about this style is capturing them! I don't speak for Guido or any other authoritative voices, that's just my take. _______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@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/OQMNNXJZR67SHPCJZ7YJ42ZQY26OVIWB/ Code of Conduct: http://python.org/psf/codeofconduct/