Re: short-circuiting any/all ?

2010-03-23 Thread Jean-Michel Pichavant
kj wrote: Arguably, Knuth's "premature optimization is the root of all evil" applies even to readability (e.g. "what's the point of making code optimally readable if one is going to change it completely next day?") The guy who will change it will have to read it. The only waste would be if the

Re: short-circuiting any/all ?

2010-03-22 Thread kj
In Steven D'Aprano writes: >On Mon, 22 Mar 2010 22:19:57 +, kj wrote: >In any case, the once-off cost of creating or importing a function is >usually quite cheap. As usual, the best advise is not to worry about >optimization until you have profiled the code and learned where the >actual

Re: short-circuiting any/all ?

2010-03-22 Thread Steven D'Aprano
On Mon, 22 Mar 2010 22:19:57 +, kj wrote: > In Tim Golden > writes: > >>On 22/03/2010 18:30, kj wrote: >>> Thanks! I'm glad to know that one can get the short circuiting using >>> a map-type idiom. (I prefer map over comprehensions when I don't need >>> to define a function just for the p

Re: short-circuiting any/all ?

2010-03-22 Thread kj
In Tim Golden writes: >On 22/03/2010 18:30, kj wrote: >> Thanks! I'm glad to know that one can get the short circuiting >> using a map-type idiom. (I prefer map over comprehensions when I >> don't need to define a function just for the purpose of passing it >> to it.) >In what way does "map"

Re: short-circuiting any/all ?

2010-03-22 Thread Tim Golden
On 22/03/2010 18:30, kj wrote: Thanks! I'm glad to know that one can get the short circuiting using a map-type idiom. (I prefer map over comprehensions when I don't need to define a function just for the purpose of passing it to it.) In what way does "map" over "comprehensions" save you defin

Re: short-circuiting any/all ?

2010-03-22 Thread kj
In <291d82b7-b13b-4f49-901c-8194f3e07...@e7g2000yqf.googlegroups.com> nn writes: >If you are in Python 3 "any(map(is_invalid, L))" should short circuit. >If you are in Python 2 use "from itertools import imap; >any(imap(is_invalid, L))" Thanks! I'm glad to know that one can get the short circu

Re: short-circuiting any/all ?

2010-03-22 Thread Raymond Hettinger
On Mar 22, 7:45 am, kj wrote: > I have a list of items L, and a test function is_invalid that checks > the validity of each item.  To check that there are no invalid > items in L, I could check the value of any(map(is_invalid, L)). > But this approach is suboptimal in the sense that, no matter wha

Re: short-circuiting any/all ?

2010-03-22 Thread nn
kj wrote: > I have a list of items L, and a test function is_invalid that checks > the validity of each item. To check that there are no invalid > items in L, I could check the value of any(map(is_invalid, L)). > But this approach is suboptimal in the sense that, no matter what > L is, is_invali

Re: short-circuiting any/all ?

2010-03-22 Thread Tim Wintle
On Mon, 2010-03-22 at 14:45 +, kj wrote: > I have a list of items L, and a test function is_invalid that checks > the validity of each item. To check that there are no invalid > items in L, I could check the value of any(map(is_invalid, L)). > But this approach is suboptimal in the sense that,

Re: short-circuiting any/all ?

2010-03-22 Thread Jean-Michel Pichavant
kj wrote: I have a list of items L, and a test function is_invalid that checks the validity of each item. To check that there are no invalid items in L, I could check the value of any(map(is_invalid, L)). But this approach is suboptimal in the sense that, no matter what L is, is_invalid will be

Re: short-circuiting any/all ?

2010-03-22 Thread Tim Golden
On 22/03/2010 14:45, kj wrote: I have a list of items L, and a test function is_invalid that checks the validity of each item. To check that there are no invalid items in L, I could check the value of any(map(is_invalid, L)). But this approach is suboptimal in the sense that, no matter what L is

short-circuiting any/all ?

2010-03-22 Thread kj
I have a list of items L, and a test function is_invalid that checks the validity of each item. To check that there are no invalid items in L, I could check the value of any(map(is_invalid, L)). But this approach is suboptimal in the sense that, no matter what L is, is_invalid will be executed