Re: [Python-Dev] Small any/all enhancement

2005-12-28 Thread Eric Nieuwland
I wrote: > all() can be terminated at the first false element. For very long > sequences this has important performance benefits. Besides, it makes > all(seq,pred) the equivalent of pred(seq[0]) and pred(seq[1]) and > pred(seq[2]) and ... then, Martin v. Löwis wrote: > > And so does the version w

Re: [Python-Dev] Small any/all enhancement

2005-12-28 Thread Alex Martelli
On Dec 27, 2005, at 11:06 PM, Eric Nieuwland wrote: ... >>> def zerop(x): >>> return x==0 >>> >>> all(some_objects, zerop) >> >> and why would that be better than >> all(o==0 for o in some_objects) >> ? > > all() can be terminated at the first false element. For very long > sequences this

Re: [Python-Dev] Small any/all enhancement

2005-12-28 Thread Martin v. Löwis
Eric Nieuwland wrote: >>all(o==0 for o in some_objects) >>? > > > all() can be terminated at the first false element. For very long > sequences this has important performance benefits. Besides, it makes > all(seq,pred) the equivalent of pred(seq[0]) and pred(seq[1]) and > pred(seq[2]) and ...

Re: [Python-Dev] Small any/all enhancement

2005-12-27 Thread Eric Nieuwland
Alex Martelli wrote: > On Dec 27, 2005, at 12:45 PM, Valentino Volonghi aka Dialtone wrote: > ... >> any(iterable, test=bool) and all(iterable, test=bool) > ... >> any(some_objects, test=operator.attrgetter('some_attribute')) > > Why would that be better than > any(o.some_attribute for o in

Re: [Python-Dev] Small any/all enhancement

2005-12-27 Thread Nick Coghlan
Bob Ippolito wrote: > I don't see the harm in a "key" argument like sorted has, but without > a key argument it could be extended to take more arguments like max/ > min do for convenience. e.g. any(a, b, c) instead of any((a, b, c)). Hmm, I think you just found the use case for fixing the curr

Re: [Python-Dev] Small any/all enhancement

2005-12-27 Thread Andrew Koenig
> Of course I already knew all the alternatives using map and the generator > expression, but I felt like mine was clearer for a reader, this is > probably true but not enough to justify the change. If there is to be any enhancement, I think I would prefer it to be an enhancement to map, so that m

Re: [Python-Dev] Small any/all enhancement

2005-12-27 Thread Bob Ippolito
On Dec 27, 2005, at 5:48 PM, Valentino Volonghi aka Dialtone wrote: > On Tue, Dec 27, 2005 at 01:50:37PM -0800, Alex Martelli wrote: > > I'll answer here for all the people who kindly answered. > >> Why would that be better than >> any(o.some_attribute for o in some_objects) >> ? > > I think it's

Re: [Python-Dev] Small any/all enhancement

2005-12-27 Thread Valentino Volonghi aka Dialtone
On Tue, Dec 27, 2005 at 01:50:37PM -0800, Alex Martelli wrote: I'll answer here for all the people who kindly answered. > Why would that be better than > any(o.some_attribute for o in some_objects) > ? I think it's because lately I've been using common lisp a lot and the approach with the test f

Re: [Python-Dev] Small any/all enhancement

2005-12-27 Thread Alex Martelli
On Dec 27, 2005, at 12:45 PM, Valentino Volonghi aka Dialtone wrote: ... > any(iterable, test=bool) and all(iterable, test=bool) ... > any(some_objects, test=operator.attrgetter('some_attribute')) Why would that be better than any(o.some_attribute for o in some_objects) ? > def zerop(x):

Re: [Python-Dev] Small any/all enhancement

2005-12-27 Thread Martin v. Löwis
Valentino Volonghi aka Dialtone wrote: > What I would like to ask, before it's too late, is if it's possible to add an > optional test argument. I don't see why: you can easily synthesize that with map/imap. > These would be the new proposed APIs. The usecase is to be able to extract > attributes

[Python-Dev] Small any/all enhancement

2005-12-27 Thread Valentino Volonghi aka Dialtone
I see that Python 2.5 will include a simple implementation of any/all. What I would like to ask, before it's too late, is if it's possible to add an optional test argument. any(iterable, test=bool) and all(iterable, test=bool) These would be the new proposed APIs. The usecase is to be able to ex