Path: csiph.com!eternal-september.org!feeder.eternal-september.org!border1.nntp.ams1.giganews.com!nntp.giganews.com!newsfeed.xs4all.nl!newsfeed7.news.xs4all.nl!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.006 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'nicely': 0.07; 'val': 0.07; 'obj': 0.09; ':-)': 0.12; 'def': 0.13; 'interpreter': 0.15; '-tkc': 0.16; 'from:addr:python.list': 0.16; 'from:addr:tim.thechases.com': 0.16; 'from:name:tim chase': 0.16; 'iterator': 0.16; 'wrote:': 0.16; 'to:name:python- list@python.org': 0.20; 'this:': 0.23; 'written': 0.24; 'header :In-Reply-To:1': 0.24; 'chris': 0.26; 'right.': 0.27; 'code': 0.30; 'becomes': 0.30; 'initially': 0.30; 'handle': 0.34; 'false': 0.35; 'something': 0.35; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'received:10': 0.37; 'charset:us-ascii': 0.37; 'to:addr:python.org': 0.40; 'easy': 0.60; 'received:50': 0.66; 'subject:membership': 0.91 X-Sender-Id: wwwh|x-authuser|tim@thechases.com X-Sender-Id: wwwh|x-authuser|tim@thechases.com X-MC-Relay: Neutral X-MailChannels-SenderId: wwwh|x-authuser|tim@thechases.com X-MailChannels-Auth-Id: wwwh X-MC-Loop-Signature: 1439125801467:1417328208 X-MC-Ingress-Time: 1439125801467 Date: Sun, 9 Aug 2015 08:09:51 -0500 From: Tim Chase To: "python-list@python.org" Subject: Re: Iterators membership testing In-Reply-To: References: <88256581-75d4-4f77-81f0-9e3e25baecbc@googlegroups.com> X-Mailer: Claws Mail 3.11.1 (GTK+ 2.24.25; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-AuthUser: tim@thechases.com X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ 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: 22 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1439126856 news.xs4all.nl 2886 [2001:888:2000:d::a6]:43837 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:95189 On 2015-08-09 19:24, Chris Angelico wrote: > That's exactly right. The only way for the interpreter to handle > 'in' on an iterator is something like this: > > def contains(iter, obj): > for val in iter: > if val == obj: return True > return False Which can nicely be written as any(i == obj for obj in iter) The addition of any/all initially struck me as a "why?! this is so easy to write in-line" moment, only to find myself using them all() the time. :-) The code-intention becomes so much clearer. Even back-ported them to 2.4 code that I maintain. -tkc