Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'example:': 0.03; 'languages,': 0.03; 'flags': 0.05; 'instance,': 0.05; 'int': 0.05; '-1;': 0.09; '3.0,': 0.09; '>>>>': 0.09; 'arithmetic': 0.09; 'bool': 0.09; 'expressions.': 0.09; 'integers': 0.09; 'values,': 0.09; 'written': 0.12; 'skip:[ 20': 0.12; 'am,': 0.14; 'debugging': 0.14; 'wrote:': 0.14; 'defined': 0.15; '(1,': 0.16; 'arithmetic,': 0.16; 'boolean': 0.16; 'constructs': 0.16; 'contrived': 0.16; 'false:': 0.16; 'flags;': 0.16; 'handy': 0.16; 'subject:() ': 0.16; 'subject:function': 0.16; 'subtract': 0.16; 'fine': 0.18; 'meant': 0.18; 'language': 0.20; 'header:In-Reply- To:1': 0.22; 'mon,': 0.22; 'values': 0.23; 'indexing': 0.23; 'integer': 0.23; 'subject:code': 0.23; 'values.': 0.23; 'possible,': 0.25; "i'm": 0.26; 'instead': 0.26; 'chris': 0.27; 'function': 0.27; 'message-id:@mail.gmail.com': 0.28; "doesn't": 0.28; 'mode': 0.29; 'accordingly.': 0.29; 'condition.': 0.29; 'functions.': 0.29; 'list': 0.30; '-1,': 0.31; 'annoying': 0.31; 'to:addr:python-list': 0.32; "i've": 0.33; 'someone': 0.33; 'array': 0.33; 'skip:" 10': 0.34; 'there': 0.35; 'print': 0.35; 'rather': 0.36; 'some': 0.37; 'received:209.85': 0.37; 'apr': 0.38; 'else,': 0.38; 'steven': 0.38; 'received:google.com': 0.38; 'but': 0.38; 'skip:" 20': 0.38; 'used': 0.38; 'though': 0.38; 'to:addr:python.org': 0.39; 'could': 0.39; 'where': 0.39; 'from:': 0.39; 'received:209': 0.39; 'except': 0.39; 'basic': 0.40; 'takes': 0.40; 'would': 0.40; "it's": 0.40; 'header:Received:5': 0.40; 'results': 0.61; '2011': 0.62; 'plus': 0.65; 'believe': 0.66; '10:22': 0.84; 'complex,': 0.84; 'received:209.85.210.174': 0.84; 'received:mail-iy0-f174.google.com': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:date :message-id:subject:from:to:content-type:content-transfer-encoding; bh=Pea5zlEHd8M/IYimZtJ4D7YLTc1rhxaKMmrgrPvzD48=; b=Ix0ljEj0Vsbewp/arNhppUC8bDEC8O/1wh6n9W7azEMT1gqzBcWjjCUYN6bQzuYzxU rm4X8mEilPQYz6uZVohA+pCTDktZ0k5Pbj/BNVFOTX1+Uvn9WAxvo61ZDIrEpx9XTqzG FyBrqyf+2pr9VymkGHu3H2VaqDmY5zkh32l0A= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; b=l9yLdTErxYM1uw50BPg/BeuYnTL6l8+bX9vZaF4x24mhSIiAGnempmECjW6xFka29h R5UYuKIWYhzq87X9fWq3JgAo7J9COYcD/wA1ceolBhoKsgGu3L+H11NZ+9rN/W2jbSd3 rjumJl7TCos2YlpCafX2bgMw2VVyMngPkkLp8= MIME-Version: 1.0 In-Reply-To: <4dab845d$0$29986$c3e8da3$5496439d@news.astraweb.com> References: <4da9fb0b$0$13696$426a74cc@news.free.fr> <87k4etho6e.fsf@benfinney.id.au> <4daa2b72$0$32037$426a74cc@news.free.fr> <87d3klha85.fsf@benfinney.id.au> <4daaa6f6$0$20187$426a74cc@news.free.fr> <878vv9gqhq.fsf@benfinney.id.au> <4dab7654$0$7290$426a74cc@news.free.fr> <4dab845d$0$29986$c3e8da3$5496439d@news.astraweb.com> Date: Mon, 18 Apr 2011 10:52:31 +1000 Subject: Re: Equivalent code to the bool() built-in function From: Chris Angelico To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 51 NNTP-Posting-Host: 82.94.164.166 X-Trace: 1303087960 news.xs4all.nl 81482 [::ffff:82.94.164.166]:52818 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:3445 On Mon, Apr 18, 2011 at 10:22 AM, Steven D'Aprano wrote: >>>> types =3D [str, complex, float, bool] >>>> [f(x) for f, x in zip(types, (1, 2, 3, 4))] > ['1', (2+0j), 3.0, True] I believe this one would work fine with a function defined as per OP - zip takes callables, which could be types or functions. > * if flags are written 0 and 1, that frequently fools people into > =A0thinking they are meant to be understood as *integer* values rather > =A0than boolean values, and they will do arithmetic on those flags; Depending on what you mean by arithmetic, that can be a good thing. I've frequently, in various languages, used booleans as though they were integers - for instance, indexing a list with an integer plus a condition. Contrived example: mode =3D 2 ... print ("default", "default-root", "modeA","modeA-root", "modeB","modeB-root", ) [mode+mode+(uid=3D=3D0)] For debugging output, where I want to keep it as self-contained as possible, constructs like these are very handy - especially as they can be embedded inside other expressions. Every language I've used except BASIC has used True =3D=3D 1, False =3D=3D = 0, but I'm sure there are some which use other values. If True =3D=3D -1, then you simply subtract the bool from the int instead of adding them. If it's something else, you arrange the array accordingly. > * there was never any consistency, people would write any of: > > =A0true =3D 1; false =3D 0 > =A0FALSE =3D 0; TRUE =3D not FALSE > =A0True =3D -1; False =3D not True Just as long as someone doesn't use: true =3D 1; false =3D -1 which results in the annoying situation that: if x =3D=3D false: is different from: if x: But on the plus side, TheDailyWTF.com is never short of publishable materia= l... Chris Angelico