Path: csiph.com!au2pb.net!feeder.erje.net!1.eu.feeder.erje.net!bcyclone05.am1.xlned.com!bcyclone05.am1.xlned.com!newsfeed.xs4all.nl!newsfeed7.news.xs4all.nl!newsgate.cistron.nl!newsgate.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; 'cc:addr:python-list': 0.09; 'obj': 0.09; 'def': 0.13; 'interpreter': 0.15; '11:09': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'iterator': 0.16; 'wrote:': 0.16; '2015': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'aug': 0.20; 'this:': 0.23; 'tim': 0.24; 'written': 0.24; 'header :In-Reply-To:1': 0.24; 'sense': 0.26; 'chris': 0.26; 'right.': 0.27; 'message-id:@mail.gmail.com': 0.27; 'chase': 0.29; "i'm": 0.30; 'another': 0.32; 'handle': 0.34; 'received:google.com': 0.35; 'false': 0.35; 'something': 0.35; 'step': 0.36; 'depends': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'sure': 0.39; 'chrisa': 0.84; "it'd": 0.84; 'to:none': 0.91; 'subject:membership': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=NAawEZQfkc65BsV3YTRYIlK6S/J0DpNR30SYSLTmJxc=; b=NKsD3XM29RrKtfZSgBKD4jvMDWtAYqzED8cAjDZZVBrzXyRy7WjLCxfYNsV+crBzbH 1qquVqdlmALjDaFMQaxwu3gOTl+ZI7flgB1FiXEexT2NcbNJhXJOiQJleuogBulnveR2 SI963VSh52NIK2l+qqPn2ZjEsUWzyAq3nXbCCNSLf803nXTQg/n5+mI8ohzNi48GNX5N 3lCAk4vM2k3rGfwCkgXbCh6X+YgLcNcFOkjWub33xZ/SX86AX1zckd3RhxcE66bEbx+c Pxlk6aa+iaib3bkhzVrSGtuUASXy7w2/kI/w9kaOGJef6t277NC9eFxJXnKvhcBWC855 ANvA== MIME-Version: 1.0 X-Received: by 10.107.163.11 with SMTP id m11mr16465088ioe.31.1439125880171; Sun, 09 Aug 2015 06:11:20 -0700 (PDT) In-Reply-To: <20150809080917.2c87f22f@bigbox.christie.dr> References: <88256581-75d4-4f77-81f0-9e3e25baecbc@googlegroups.com> <20150809080917.2c87f22f@bigbox.christie.dr> Date: Sun, 9 Aug 2015 23:11:20 +1000 Subject: Re: Iterators membership testing From: Chris Angelico Cc: "python-list@python.org" Content-Type: text/plain; charset=UTF-8 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: 19 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1439125888 news.xs4all.nl 2827 [2001:888:2000:d::a6]:40890 X-Complaints-To: abuse@xs4all.nl X-Received-Bytes: 3716 X-Received-Body-CRC: 201048748 Xref: csiph.com comp.lang.python:95188 On Sun, Aug 9, 2015 at 11:09 PM, Tim Chase wrote: > 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) Indeed it can, although I'm not sure whether it'd just have been another step in the explanation :) Whether or not that makes perfect sense depends on the reader. ChrisA