Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed5.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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'bug': 0.02; 'cpython': 0.05; 'terry': 0.07; 'assert': 0.09; 'dict': 0.09; 'cc:addr :python-list': 0.15; '-tkc': 0.16; 'from:addr:python.list': 0.16; 'from:addr:tim.thechases.com': 0.16; 'from:name:tim chase': 0.16; 'iterates': 0.16; 'message-id:@tim.thechases.com': 0.16; 'received:70.251': 0.16; 'received:dsl.rcsntx.swbell.net': 0.16; 'received:rcsntx.swbell.net': 0.16; 'received:swbell.net': 0.16; 'reedy': 0.16; 'wrote:': 0.18; 'cc:no real name:2**0': 0.21; 'is?': 0.21; 'maybe': 0.21; '(or': 0.22; 'items.': 0.23; "shouldn't": 0.23; 'header:In-Reply-To:1': 0.23; 'cc:2**0': 0.25; '(and': 0.28; 'depends': 0.28; 'cc:addr:python.org': 0.29; 'hash': 0.30; 'list1': 0.30; 'url:library': 0.30; "didn't": 0.30; 'least': 0.31; 'changes': 0.32; 'does': 0.32; 'sort': 0.32; 'there': 0.33; 'header:User-Agent:1': 0.33; 'hold': 0.35; 'url:python': 0.35; 'anything': 0.36; 'depend': 0.36; 'entry': 0.37; 'but': 0.37; 'two': 0.37; 'experience,': 0.38; 'url:org': 0.38; 'url:docs': 0.38; 'subject:: ': 0.39; 'order': 0.62; 'saw': 0.67; 'order,': 0.73; 'it"': 0.84 Date: Thu, 03 Nov 2011 18:01:38 -0500 From: Tim Chase User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.20) Gecko/20110826 Icedove/3.1.12 MIME-Version: 1.0 To: Terry Reedy Subject: Re: Dictionary sorting References: <16245908.783.1320346014867.JavaMail.geo-discussion-forums@yqhd1> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed 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 - tim.thechases.com X-Source: X-Source-Args: X-Source-Dir: Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 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: 1320361310 news.xs4all.nl 6881 [2001:888:2000:d::a6]:48877 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:15311 On 11/03/11 16:36, Terry Reedy wrote: > > Is there a way to not sort them and leave the order as is? > > CPython iterates (and prints) dict items in their arbitrary internal > hash table order, which depends on the number and entry order of the > items. It is a bug to depend on that arbitrary order in any way. Does this "never trust it" hold even for two consecutive iterations over an unchanged dict? I didn't see anything in the docs[1] to make such a claim, but at least from my experience, one can reliably assert d = {} randomly_populate(d) list1 = list(d.iterkeys()) list2 = list(d.iterkeys()) assert list1 == list2 I understand all bets are off if one adds/removes (or maybe changes the values) of the dict between iterations, but I didn't know if what I saw was merely an implementation detail that shouldn't be counted on. -tkc [1] http://docs.python.org/library/stdtypes.html#mapping-types-dict