Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!eternal-september.org!feeder.eternal-september.org!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!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.012 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'example:': 0.03; 'element': 0.07; 'sake': 0.09; 'subject:iterable': 0.09; 'cc:addr :python-list': 0.11; 'itself.': 0.14; 'duplicates': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'iterable)': 0.16; 'iterating': 0.16; 'iteration': 0.16; 'once.': 0.16; 'roy': 0.16; 'wrote:': 0.18; 'cc:addr:python.org': 0.22; 'print': 0.22; "shouldn't": 0.24; 'cc:2**0': 0.24; '(for': 0.26; 'header:In-Reply-To:1': 0.27; 'chris': 0.29; 'am,': 0.29; 'compared': 0.30; 'message-id:@mail.gmail.com': 0.30; 'that.': 0.31; 'sep': 0.31; 'with,': 0.31; 'probably': 0.32; 'fri,': 0.33; 'but': 0.35; 'received:google.com': 0.35; 'subject:?': 0.36; 'does': 0.39; 'skip:b 40': 0.39; 'new': 0.61; "you're": 0.61; 'pick': 0.64; 'smith': 0.68; 'subject:there': 0.68; 'therefore': 0.72; 'bag': 0.74; 'article': 0.77; 'subject:check': 0.84; 'to:none': 0.92 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=fISp1qIii4HN5PklQiFTYH/ww6/lc8BenO65NdfBa38=; b=A7wz7iXgp7nuJXRkaCNoaAxq87ZEdIpbY/+j/zDKj8I5kA54Uju+R/HzDFavveX/GF K6VFzI+Xp1Pk7F0r76Wgt9SaiCwt0yMEZGqTfcz+dYyL9EXQkYrahiXnRA1y9Dceovuv akhITZaw1pyNOEDrRojq7wiVxh3GumGAFBRt0mWFtUBgP9i5woZQCGPdb0/Ik8OOLWnS pkPoWlMmTnaJ3WHxm9uk8hXvJaPhcOOaXbNT6aF0Dt3mAN8ZxAmH426LZ3tCf1Nt/oc4 wRHSCNEtD/s1elWm1PwgSKOcuYmwTzHXcVVz1RH7cJgTdTTI00EF482thPPGW7je2s0Y MJng== MIME-Version: 1.0 X-Received: by 10.50.117.65 with SMTP id kc1mr4344124igb.34.1411094711909; Thu, 18 Sep 2014 19:45:11 -0700 (PDT) In-Reply-To: References: Date: Fri, 19 Sep 2014 12:45:11 +1000 Subject: Re: Is there a canonical way to check whether an iterable is ordered? 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.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: 22 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1411094714 news.xs4all.nl 2953 [2001:888:2000:d::a6]:52819 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:78054 On Fri, Sep 19, 2014 at 9:52 AM, Roy Smith wrote: > In article , > Chris Angelico wrote: > >> The one thing you can rely on (and therefore must comply with, when >> you design an iterable) is that iteration will hit every element >> exactly once. > > Does it actually say that somewhere? For example: > > for i in bag.pick_randomly_with_replacement(n=5): > print i > > shouldn't do that. When you pick randomly from a population, you create a new population, which may have duplicates compared to the original. (For efficiency's sake it probably won't all actually exist immediately, but conceptually it does exist.) That's what you're iterating over - not the bag itself. ChrisA