Any, All predicates (and vector operations for free)

Christos TZOTZIOY Georgiou DLNXPEGFQVEB at spammotel.com
Sun Feb 16 10:18:50 EST 2003


On Sun, 16 Feb 2003 15:32:36 +0100, rumours say that Alex Martelli
<aleaxit at yahoo.com> might have written:

>> BTW, would you consider these as a worthy candidate for inclusion in the
>> standard library?  Do you often need to check that some condition
>> applies to all items of a sequence?  If yes, please suggest any changes
>
>No to the first, yes to the second.  In the frequent case in which I
>want to test if some property holds on every item of an iterable (and
>your code only works on sequences, plus a few other special iterables
>such as dicts, NOT on many other iterables such as files and generators,
>because for example it relies on len(), and most iterables don't and
>can't support that),

Yes, you are correct about sequences and not iterables.  So to be
precise, I should either:
- replace _iterable with _sequence
- change __nonzero__ to not use len, and perhaps avoid _new_result by
building the result list with .append

>almost invariably I much prefer to bail out as soon
>as a non-compliant item is found, rather than having to operate on all
>items willy-nilly.  I find such semantics generally more important than
>the "neat-o" syntax afforded by operator overloading.

I care about speed too; this code actually was written before generators
initially, and while I have introduced some 2.3 syntax in it, I have not
yet attempted to turn this into a class using generators... perhaps
adding a .next method would not be such a bad start :)

Thanks for replying, Alex.
-- 
TZOTZIOY, I speak England very best,
Real email address: 'dHpvdEBzaWwtdGVjLmdy\n'.decode('base64')




More information about the Python-list mailing list