Guido's thinking about ditching lambda, reduce(), filter() and map(). I don't use any of them, so I'd be quite happy to see them go, and the proposed product(), any() and all() functions look really good.
I'm with Peter, though - they shoudn't be builtins. We have enough of those already. I seem to remember the martellibot proposing a reductions module at some point. That would be a much better place for them - and for sum(), for that matter. Not only would that avoid bloating the builtins, it would also help to avoid the problem of people already having objects named 'any' or 'all'.
Posted to Python by Simon Brunning at March 11, 2005 01:36 PMWhy does it hurt to have a couple more builtins? They just sit there harmlessly, they don't hurt anyone, they don't require heavy lifting.
Posted by: Ian Bicking on March 11, 2005 11:29 PMFor little pieces of functionality, an in-line lambda can often be slipped in. In that case, a nested function would add at least three lines: the def, the return statement, and the blank line separating it from the rest of the code.
Even so, I don't use lambda much so it wouldn't be a deal-breaker if it were removed from the language.
Posted by: Alan Green on March 12, 2005 09:55 AMWell, I'm sure nested function one-liners would become accepted practice if lambda went away.
Posted by: Bob Ippolito on March 13, 2005 01:08 AMEverything in the builtins is effectively a reserved word. (I know that it's not *really* a reserved word, but it's bad style, it's *really* bad style, to use a builtin's name for anything else.) That's why I would like to see the set of builtins kept as small as possible.
BTW, Greg Ewing suggested over on python-dev that we don't necessarily need a *new* module here - this stuff all fits into the itertools module pretty well. I'm about a +0.5 on that.
Posted by: Simon Brunning on March 14, 2005 09:15 AMThe only place I use lambda is when getting back a query from a database where I'm selecting a single column from a table (eg, "select name from user"). In this case the you get a a tuple of single-element tuples (eg, (('Simon',),('Bob',),('Alan',),('Ian',)) ). I'll embed the query in a map(lambda x: x[0], db.query(...)). I get rid of the inner single-element tuples and can safely do a "for name in names:" where if I don't do that a "for name, in names:" will throw an exception on the query getting an empty answer.
I know I could do
for name in names:
something = name[0]
but I don't like it.
There's probably a better way without using a lambda, but it works for me.
Posted by: Hank on March 16, 2005 12:00 AMHank: [x[0] for x in db.query(...)], or if you want to use the map(), operator.itemgetter(0) creates for you what you take lambda for.
All the others:
from itertools import * # There, wasn't that easy?