Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #3560

Re: Equivalent code to the bool() built-in function

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <anikom15@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.019
X-Spam-Evidence '*H*': 0.96; '*S*': 0.00; 'exception.': 0.09; 'pm,': 0.11; '>>>': 0.12; 'slightly': 0.12; 'binary': 0.14; 'wrote:': 0.14; '(another': 0.16; '(last': 0.16; 'boolean': 0.16; 'contrived': 0.16; 'exploits': 0.16; 'expression)': 0.16; 'false)': 0.16; 'mean,': 0.16; 'met.': 0.16; 'packet': 0.16; 'situations,': 0.16; 'subject:() ': 0.16; 'subject:function': 0.16; 'tue,': 0.20; 'maybe': 0.21; 'header:In-Reply-To:1': 0.22; 'posted': 0.22; 'subject:code': 0.23; 'example': 0.24; 'received:209.85.212': 0.25; 'compare': 0.26; 'equivalent': 0.26; 'chris': 0.27; 'raise': 0.29; "won't": 0.30; 'skip:( 20': 0.31; 'guarantees': 0.31; 'recall': 0.31; 'does': 0.31; "can't": 0.31; 'to:addr:python-list': 0.32; '...': 0.32; "i've": 0.33; 'done,': 0.33; 'from:charset:iso-8859-1': 0.33; 'fairly': 0.33; "isn't": 0.34; 'received:192': 0.34; 'received:192.168.0': 0.35; 'christian': 0.35; 'flag': 0.35; 'received:192.168': 0.37; 'case': 0.37; 'received:209.85': 0.37; 'useful': 0.37; 'apr': 0.38; 'steven': 0.38; 'received:google.com': 0.38; 'but': 0.38; 'explain': 0.39; 'to:addr:python.org': 0.39; 'where': 0.39; 'received:209': 0.39; 'header:Mime-Version:1': 0.39; 'how': 0.39; 'would': 0.40; 'header:Received:5': 0.40; 'direct': 0.61; '2011': 0.62; 'message-id:@localhost.localdomain': 0.74; 'guarantee': 0.75; 'exclusive': 0.77; 'satisfied': 0.83; 'concept:': 0.84; 'specifics': 0.84; 'suspicious': 0.84; 'sum': 0.89; 'or:': 0.91
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:subject:from:to:in-reply-to:references :content-type:date:message-id:mime-version:x-mailer :content-transfer-encoding; bh=sOd/Me2oiwbx0e2xcm52OkCv1KUu/jz1TDq2cXipNKQ=; b=GOepY7GxZ7pldAbvHKUEtdVRf86QKq6AOdyRN4aHH2iLT+TKlNwjkFhspSdWb213Kt FZuGvJI1kunsvJRlMxKChHEuj5Aw5oc/PhXSyizTjkk1RdtCUiVmg/6X/J3mRQ+9BjmE jx0LIwqVK5Nwn1mN4MvS03DVl9OayUnZ+3lDw=
DomainKey-Signature a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=subject:from:to:in-reply-to:references:content-type:date:message-id :mime-version:x-mailer:content-transfer-encoding; b=LQF65AzNxhI1itim9N+/HOWP1i1WFjVo9Jwn6VOczZ0Nhjj70eowToUTlp7jSK2pm1 R2tn48V6R6MfqaJ0cg2V1Bmz4I0JTsxC6McIDgtVBnoPjyq+IzijMCvGt/2udHUl29VP g8GRNIe9ddBgehKIpzjz0/CdW9gvrPeYUq71o=
Subject Re: Equivalent code to the bool() built-in function
From Westley Martínez <anikom15@gmail.com>
To python-list@python.org
In-Reply-To <BANLkTi=K+jNchynoomeN9aeMY4gqUHvJ4A@mail.gmail.com>
References <4da9fb0b$0$13696$426a74cc@news.free.fr> <mailman.442.1302987518.9059.python-list@python.org> <87k4etho6e.fsf@benfinney.id.au> <4daa2b72$0$32037$426a74cc@news.free.fr> <87d3klha85.fsf@benfinney.id.au> <4daaa6f6$0$20187$426a74cc@news.free.fr> <mailman.453.1303029985.9059.python-list@python.org> <911dvfF6ocU1@mid.individual.net> <4dac97ca$0$10609$742ec2ed@news.sonic.net> <ioip56$btd$1@dough.gmane.org> <BANLkTi=C9nz7zVvBr0nPMiKgO9hkWo2uKA@mail.gmail.com> <mailman.549.1303194413.9059.python-list@python.org> <4dad4b29$0$29984$c3e8da3$5496439d@news.astraweb.com> <BANLkTi=K+jNchynoomeN9aeMY4gqUHvJ4A@mail.gmail.com>
Content-Type text/plain; charset="UTF-8"
Date Tue, 19 Apr 2011 06:43:45 -0700
Mime-Version 1.0
X-Mailer Evolution 2.32.2
Content-Transfer-Encoding 7bit
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.559.1303220632.9059.python-list@python.org> (permalink)
Lines 41
NNTP-Posting-Host 82.94.164.166
X-Trace 1303220633 news.xs4all.nl 41103 [::ffff:82.94.164.166]:46587
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:3560

Show key headers only | View raw


On Tue, 2011-04-19 at 19:00 +1000, Chris Angelico wrote:
> On Tue, Apr 19, 2011 at 6:43 PM, Steven D'Aprano
> <steve+comp.lang.python@pearwood.info> wrote:
> > but I don't see how
> >
> > (arbitrary expression) + (another expression) + ... + (last expression)
> >
> > can have any guarantees applied. I mean, you can't even guarantee that
> > they won't raise an exception. Can you explain what you mean?
> 
> What Christian posted isn't something I've often done, but here's
> something slightly different that exploits the same
> comparisons-return-summable-values concept:
> 
> A condition with N subconditions is deemed to be satisfied if a
> minimum of M of them are true. This is a general case of the boolean
> Or (N = 2, M = 1) and And (N = 2, M = 2), but does not have a direct
> equivalent in binary operators. You simply sum the subconditions,
> compare against M, and you have your answer.
> 
> if (((port<1024) + (!ip.startswith("192.168.")) +
> (greylist[ip]>time()) + (++spewcnt>10))>=3) // flag this packet as
> suspicious
> 
> Contrived example as I don't recall any specifics right now, but this
> will pick up any packets where three or more of the conditions are
> met. Useful only in fairly specific situations, but I don't know of
> any way to do this with just AND/OR/NOT that would be as clear and
> simple.
> 
> Chris Angelico

Exclusive or:
>>> if not (True and False and False and False) or
           (False and True and False and False) or
           (False and False and True and False) or
           (False and False and False and True):
...     print(True)

Maybe a little silly.

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Equivalent code to the bool() built-in function candide <candide@free.invalid> - 2011-04-16 22:24 +0200
  Re: Equivalent code to the bool() built-in function Chris Rebert <clp2@rebertia.com> - 2011-04-16 13:58 -0700
    Re: Equivalent code to the bool() built-in function Ben Finney <ben+python@benfinney.id.au> - 2011-04-17 07:38 +1000
      Re: Equivalent code to the bool() built-in function candide <candide@free.invalid> - 2011-04-17 01:51 +0200
        Re: Equivalent code to the bool() built-in function Chris Rebert <clp2@rebertia.com> - 2011-04-16 17:16 -0700
        Re: Equivalent code to the bool() built-in function Ben Finney <ben+python@benfinney.id.au> - 2011-04-17 12:39 +1000
          Re: Equivalent code to the bool() built-in function candide <candide@free.invalid> - 2011-04-17 10:38 +0200
            Re: Equivalent code to the bool() built-in function Chris Angelico <rosuav@gmail.com> - 2011-04-17 18:46 +1000
              Re: Equivalent code to the bool() built-in function Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2011-04-18 12:12 +1200
                Re: Equivalent code to the bool() built-in function John Nagle <nagle@animats.com> - 2011-04-18 12:58 -0700
                Re: Equivalent code to the bool() built-in function Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2011-04-19 12:18 +1200
                Re: Equivalent code to the bool() built-in function Christian Heimes <lists@cheimes.de> - 2011-04-19 03:39 +0200
                Re: Equivalent code to the bool() built-in function Kushal Kumaran <kushal.kumaran+python@gmail.com> - 2011-04-19 11:53 +0530
                Re: Equivalent code to the bool() built-in function Grant Edwards <invalid@invalid.invalid> - 2011-04-19 14:23 +0000
                Re: Equivalent code to the bool() built-in function Jean-Paul Calderone <calderone.jeanpaul@gmail.com> - 2011-04-19 08:43 -0700
                Re: Equivalent code to the bool() built-in function Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2011-04-20 11:59 +1200
                Re: Equivalent code to the bool() built-in function Chris Angelico <rosuav@gmail.com> - 2011-04-19 16:26 +1000
                Re: Equivalent code to the bool() built-in function Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-04-19 08:43 +0000
                Re: Equivalent code to the bool() built-in function Chris Angelico <rosuav@gmail.com> - 2011-04-19 19:00 +1000
                Re: Equivalent code to the bool() built-in function Westley Martínez <anikom15@gmail.com> - 2011-04-19 06:43 -0700
            Re: Equivalent code to the bool() built-in function Ben Finney <ben+python@benfinney.id.au> - 2011-04-17 19:46 +1000
              Re: Equivalent code to the bool() built-in function candide <candide@free.invalid> - 2011-04-18 01:22 +0200
                Re: Equivalent code to the bool() built-in function Ben Finney <ben+python@benfinney.id.au> - 2011-04-18 09:46 +1000
                Re: Equivalent code to the bool() built-in function Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2011-04-18 12:08 +1200
                Re: Equivalent code to the bool() built-in function Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-04-18 00:22 +0000
                Re: Equivalent code to the bool() built-in function Chris Angelico <rosuav@gmail.com> - 2011-04-18 10:52 +1000
                Re: Equivalent code to the bool() built-in function Duncan Booth <duncan.booth@invalid.invalid> - 2011-04-18 10:01 +0000
            Re: Equivalent code to the bool() built-in function Daniel Kluev <dan.kluev@gmail.com> - 2011-04-17 21:11 +1100
      Re: Equivalent code to the bool() built-in function Daniel Kluev <dan.kluev@gmail.com> - 2011-04-18 10:45 +1100
        Re: Equivalent code to the bool() built-in function Ben Finney <ben+python@benfinney.id.au> - 2011-04-18 10:36 +1000
      Re: Re: Equivalent code to the bool() built-in function Chris Angelico <rosuav@gmail.com> - 2011-04-18 11:52 +1000
      Re: Re: Equivalent code to the bool() built-in function Dave Angel <davea@ieee.org> - 2011-04-17 21:46 -0400
      Re: Re: Equivalent code to the bool() built-in function Daniel Kluev <dan.kluev@gmail.com> - 2011-04-18 14:16 +1100
      Re: Equivalent code to the bool() built-in function Ned Deily <nad@acm.org> - 2011-04-17 21:40 -0700
      Re: Equivalent code to the bool() built-in function Chris Angelico <rosuav@gmail.com> - 2011-04-18 14:53 +1000
        Re: Equivalent code to the bool() built-in function Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2011-04-19 12:22 +1200
      Re: Equivalent code to the bool() built-in function Chris Rebert <clp2@rebertia.com> - 2011-04-17 22:49 -0700
        Re: Equivalent code to the bool() built-in function Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-04-18 06:14 +0000
      Re: Equivalent code to the bool() built-in function Chris Angelico <rosuav@gmail.com> - 2011-04-18 16:03 +1000
  Re: Equivalent code to the bool() built-in function Ben Finney <ben+python@benfinney.id.au> - 2011-04-17 07:13 +1000
    Re: Equivalent code to the bool() built-in function candide <candide@free.invalid> - 2011-04-17 01:51 +0200
  Re: Equivalent code to the bool() built-in function Raymond Hettinger <python@rcn.com> - 2011-04-18 01:33 -0700
    Re: Equivalent code to the bool() built-in function candide <candide@free.invalid> - 2011-04-18 11:19 +0200

csiph-web