Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.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; 'correspond': 0.09; 'iterate': 0.09; 'keys,': 0.09; 'oh,': 0.09; 'subject:iterable': 0.09; 'cc:addr:python-list': 0.11; 'dict': 0.16; 'fails.': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'interpreter,': 0.16; 'iterables': 0.16; 'modified.': 0.16; 'sure.': 0.16; 'wrote:': 0.18; 'rules': 0.22; 'cc:addr:python.org': 0.22; 'cc:2**0': 0.24; 'this:': 0.26; 'second': 0.26; 'values': 0.27; 'header:In-Reply-To:1': 0.27; 'message-id:@mail.gmail.com': 0.30; 'assert': 0.31; "d'aprano": 0.31; 'keys': 0.31; 'sep': 0.31; 'steven': 0.31; 'run': 0.32; 'says': 0.33; 'fri,': 0.33; 'guess': 0.33; 'problem': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'subject:?': 0.36; 'changing': 0.37; 'being': 0.38; 'pm,': 0.38; 'first': 0.61; 'back': 0.62; 'promise': 0.68; 'subject:there': 0.68; 'other.': 0.75; 'dict,': 0.84; '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=UycjDAm+MJrgRDGEe8YTjAJKTeac9QB8tmlxVW2AeHw=; b=Vq9x6i8bWRSTT3vdelGWf1zurHr1ua+jDB+TJMb0seI7rrEttFc+J7XsFHnh7tO03m ZmCNdCrqPTlsTnH7onmO94rtX6rHi/A+YEBRG9wVIkBm1CyL0gKltdDY2HS/B3T+fgvj xZ6ZKltbjxxMEl+HD51DlYz49Dd35qjEsVruXi2R1cF1Kq+3x04dxAscTzpt8IIYyCcC iHx4MxukxT45Ijs+Y91Vw8dX4+GTCUMZGnkA62hXitXNPct9Ya1vEXDryAioGqQoR8g1 5z77bUjfc9uU2h4/F3RaHR8MFuDsekwAa5OLG59oCov9pRUvAMzKjSwQv8lwpmL5G/1P P7Qw== MIME-Version: 1.0 X-Received: by 10.50.66.234 with SMTP id i10mr39792794igt.34.1411128407566; Fri, 19 Sep 2014 05:06:47 -0700 (PDT) In-Reply-To: <541c1a7b$0$29976$c3e8da3$5496439d@news.astraweb.com> References: <541bbbe6$0$29982$c3e8da3$5496439d@news.astraweb.com> <541c0c7d$0$29992$c3e8da3$5496439d@news.astraweb.com> <541c1a7b$0$29976$c3e8da3$5496439d@news.astraweb.com> Date: Fri, 19 Sep 2014 22:06:47 +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: 28 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1411128833 news.xs4all.nl 2884 [2001:888:2000:d::a6]:57977 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:78075 On Fri, Sep 19, 2014 at 9:58 PM, Steven D'Aprano wrote: > All it says is that keys/values/items will correspond, not keys/keys, etc. > > Hmmm. On second thought, there is a problem with this: > > a = list(mydict) > c = list(mydict.items()) # now the internal order is shuffled > b = list(mydict.values()) > assert list(zip(a, b)) == c > > and the assertion fails. > > So I guess that rules out dict internal order changing during a single run > of the interpreter, unless the dict is modified. Precisely. If you iterate keys, keys, values with no mutations in between, the first keys has to correspond to values, and the second keys has to correspond to values, ergo they must correspond to each other. > Anyway, that's just dicts. Custom iterables can change any time they like. Oh, sure. That's a very specific promise of the dict, nothing else. The set might well randomize, if it wished. But we still come back to there being no reason for it to change. ChrisA