Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsreader4.netcologne.de!news.netcologne.de!xlned.com!feeder1.xlned.com!newsfeed.xs4all.nl!newsfeed3a.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.037 X-Spam-Evidence: '*H*': 0.93; '*S*': 0.00; 'subject:not': 0.03; 'subject:two': 0.07; 'subject:None': 0.09; 'cc:addr:python-list': 0.11; '-tkc': 0.16; 'from:name:tim chase': 0.16; 'iterable:': 0.16; 'iteration': 0.16; 'roy': 0.16; 'wrote:': 0.18; 'written': 0.21; 'tests': 0.22; 'cc:addr:python.org': 0.22; 'cc:2**1': 0.23; 'cc:no real name:2**0': 0.24; 'header:In-Reply-To:1': 0.27; 'correct': 0.29; 'tim': 0.29; 'chase': 0.31; 'cases': 0.33; 'could': 0.34; 'possible.': 0.35; 'something': 0.35; 'test': 0.35; 'version': 0.36; 'doing': 0.36; 'useful': 0.36; 'charset:us- ascii': 0.36; 'two': 0.37; 'mine': 0.38; 'pm,': 0.38; 'even': 0.60; 'happen': 0.63; 'more': 0.64; 'mar': 0.68; 'smith': 0.68; 'as:': 0.81; '2014,': 0.84; 'clearer': 0.84; 'received:50.22': 0.84 Date: Sat, 29 Mar 2014 17:46:53 -0500 From: Tim Chase To: Roy Smith Subject: Re: checking if two things do not equal None In-Reply-To: References: <0245aca0-c6b7-493a-aa52-2c3ef6462dbd@googlegroups.com> <5337195f$0$29994$c3e8da3$5496439d@news.astraweb.com> <20140329173655.4022d715@bigbox.christie.dr> X-Mailer: Claws Mail 3.8.1 (GTK+ 2.24.10; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - boston.accountservergroup.com X-AntiAbuse: Original Domain - python.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - thechases.com X-Get-Message-Sender-Via: boston.accountservergroup.com: authenticated_id: tim@thechases.com Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 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: 30 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1396133206 news.xs4all.nl 2860 [2001:888:2000:d::a6]:43302 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:69352 On 2014-03-29 18:41, Roy Smith wrote: > On Mar 29, 2014, at 6:36 PM, Tim Chase wrote: > > > And for cases where you have more than one or two things to test > > for None-itude, you could use > > > > if all(x is None for x in [a, b, c, d]): > > do_something_if_theyre_all_None() > > I might have written that as: > > if set([a, b, c, d]) == set(None) > > That's even clearer if you happen to already have the items in an > iterable: > > if set(conditions) == set(None) Though am I correct that your iteration tests for equality, while mine tests for identity? Also, my version bails early in the event quitting early is possible. That's particularly useful in the case of doing something like if all(x() is None for x in [func1, func2, func3, costly_func]): do_something() -tkc