[Python-Dev] Shorthand for lambda

Josiah Carlson jcarlson at uci.edu
Wed Mar 23 22:26:44 CET 2005


Ka-Ping Yee <python-dev at zesty.ca> wrote:
> 
> On Wed, 23 Mar 2005, Josiah Carlson wrote:
> > Paul Moore <p.f.moore at gmail.com> wrote:
> > > I thought about it, but couldn't convince myself that it would work
> > > properly in all cases. I was thinking in terms of operator overloading
> > > of everything possible - how did you do it?
> >
> > PyTables allows something very similar for "in-kernel" searches of data,
> > but only on a single constraint.  I would imagine that Ka-Ping did it by
> > only allowing a single operation per item.
> 
> You can do more than one operation, but the usage is still quite limited.
> The item placeholder must be the first operand for it to work.
> 
>     >>> numbers = [3, 8, 4, 1, 2]
>     >>> filter(_ < 5, numbers)
>     [3, 4, 1, 2]
>     >>> map(_ * 5 + 7, numbers)
>     [10, 15, 11, 8, 9]

Your implementation "works" by not crashing, but that last map should
certainly return [22, 47, 27, 12, 17] rather than what it does.

It may be extensible to actually work the way I expect such operations
to work.

 - Josiah



More information about the Python-Dev mailing list