Re: testing array of logicals

2006-08-07 Thread H J van Rooyen
"Janto Dreijer" <[EMAIL PROTECTED]> wrote: | | Janto Dreijer wrote: | > John Henry wrote: | > > Simon Forman wrote: | > > > > | > > > > False not in logflags | > > > > | > > > | > > > Or, if your values aren't already bools | > > > | > > > False not in (bool(n) for n in logflags) | > > | > > Ve

Re: testing array of logicals

2006-08-05 Thread Simon Forman
Janto Dreijer wrote: > Janto Dreijer wrote: > > John Henry wrote: > > > Simon Forman wrote: > > > > > > > > > > False not in logflags > > > > > > > > > > > > > Or, if your values aren't already bools > > > > > > > > False not in (bool(n) for n in logflags) > > > > > > Very intriguing use of "not in

Re: testing array of logicals

2006-08-05 Thread Janto Dreijer
Janto Dreijer wrote: > John Henry wrote: > > Simon Forman wrote: > > > > > > > > False not in logflags > > > > > > > > > > Or, if your values aren't already bools > > > > > > False not in (bool(n) for n in logflags) > > > > Very intriguing use of "not in"... > > Is there a reason why you didn't wr

Re: testing array of logicals

2006-08-05 Thread Janto Dreijer
John Henry wrote: > Simon Forman wrote: > > > > > > False not in logflags > > > > > > > Or, if your values aren't already bools > > > > False not in (bool(n) for n in logflags) > > Very intriguing use of "not in"... Is there a reason why you didn't write True in (bool(n) for n in logflags) -- h

Re: testing array of logicals

2006-07-13 Thread John Henry
Simon Forman wrote: > > > > False not in logflags > > > > Or, if your values aren't already bools > > False not in (bool(n) for n in logflags) > > > > Peace, > ~Simon Very intriguing use of "not in"... Thanks, -- http://mail.python.org/mailman/listinfo/python-list

Re: testing array of logicals

2006-07-13 Thread Simon Forman
> > False not in logflags > Or, if your values aren't already bools False not in (bool(n) for n in logflags) Peace, ~Simon -- http://mail.python.org/mailman/listinfo/python-list

Re: testing array of logicals

2006-07-13 Thread Simon Forman
John Henry wrote: > Hi list, > > Is there a more elagant way of doing this? > > # logflags is an array of logicals > test=True > for x in logflags: >test = test and x > print test > > -- > Thanks, So many ways *drool* How about: False not in logflags (Anybody gonna run all these throu

Re: testing array of logicals

2006-07-13 Thread Bruno Desthuilliers
Simon Brunning a écrit : > On 13 Jul 2006 05:45:21 -0700, John Henry <[EMAIL PROTECTED]> wrote: > >> >> Simon Brunning wrote: >> > >> > min(logflags) >> > >> >> !!! > > > Be aware that not only is this an outrageous misuse of min(), +1 QOTW Ho, my, I've already proposed another one today :( --

Re: testing array of logicals

2006-07-13 Thread Simon Brunning
On 13 Jul 2006 05:45:21 -0700, John Henry <[EMAIL PROTECTED]> wrote: > > Simon Brunning wrote: > > > > min(logflags) > > > > !!! Be aware that not only is this an outrageous misuse of min(), it's also almost certainly much less efficient than /F's suggestion, 'cos it always iterates through the en

Re: testing array of logicals

2006-07-13 Thread John Henry
Simon Brunning wrote: > On 12 Jul 2006 11:14:43 -0700, John Henry <[EMAIL PROTECTED]> wrote: > > Is there a more elagant way of doing this? > > > > # logflags is an array of logicals > > test=True > > for x in logflags: > >test = test and x > > print test > > min(logflags) > !!! > I feel di

Re: testing array of logicals

2006-07-13 Thread Simon Brunning
On 12 Jul 2006 11:14:43 -0700, John Henry <[EMAIL PROTECTED]> wrote: > Is there a more elagant way of doing this? > > # logflags is an array of logicals > test=True > for x in logflags: >test = test and x > print test min(logflags) I feel dirty now. ;-) -- Cheers, Simon B, [EMAIL PROTECTED]

Re: testing array of logicals

2006-07-12 Thread Paul Rubin
"John Henry" <[EMAIL PROTECTED]> writes: > # logflags is an array of logicals > test=True > for x in logflags: >test = test and x > print test print (False not in map(bool, logflags)) Possibly more "pure" alternative (untested): from operator import and_ print reduce(and_, map(bo

Re: testing array of logicals

2006-07-12 Thread Alex Martelli
John Henry <[EMAIL PROTECTED]> wrote: > Hi list, > > Is there a more elagant way of doing this? > > # logflags is an array of logicals > test=True > for x in logflags: >test = test and x > print test test = sum(bool(x) for x in logflags)==len(logflags) is yet another possibility (without t

Re: testing array of logicals

2006-07-12 Thread Gary Herron
John Henry wrote: > Hi list, > > Is there a more elagant way of doing this? > > # logflags is an array of logicals > test=True > for x in logflags: >test = test and x > print test > > -- > Thanks, > > The builtin "reduce" does that kind of thing for any function you wish to apply across the

Re: testing array of logicals

2006-07-12 Thread Ant
John Henry wrote: > Hi list, > > Is there a more elagant way of doing this? > > # logflags is an array of logicals > test=True > for x in logflags: >test = test and x > print test There's reduce, but it's not as explicit, and see F's post RE efficiency: >>> x = [True, True, True] >>> y = [Tr

Re: testing array of logicals

2006-07-12 Thread Stefan Behnel
John Henry wrote: > Is there a more elagant way of doing this? > > # logflags is an array of logicals > test=True > for x in logflags: >test = test and x > print test Py2.5: test = all( logflags ) Py2.4 (although somewhat ugly): try: test = itertools.ifilterfalse( logflags ).next()

Re: testing array of logicals

2006-07-12 Thread Fredrik Lundh
John Henry wrote: > Is there a more elagant way of doing this? > > # logflags is an array of logicals > test=True > for x in logflags: >test = test and x > print test your code checks all members, even if the first one's false. that's not very elegant. here's a better way to do it: