Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed6.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.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'bug': 0.02; 'newbie': 0.03; 'cpython': 0.05; 'received:verizon.net': 0.07; 'terry': 0.07; 'typed': 0.07; 'python': 0.08; 'dict': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:80.91.229.12': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'received:lo.gmane.org': 0.09; 'entries': 0.15; 'iterates': 0.16; 'reedy': 0.16; 'somehow.': 0.16; 'wrote:': 0.18; 'jan': 0.19; 'is?': 0.21; 'items.': 0.23; 'header:In-Reply- To:1': 0.23; 'creating': 0.25; '(and': 0.28; 'depends': 0.28; 'print': 0.29; 'seem': 0.30; 'hash': 0.30; 'pm,': 0.31; 'sort': 0.32; 'to:addr:python-list': 0.32; 'there': 0.33; 'header:User- Agent:1': 0.33; 'header:X-Complaints-To:1': 0.33; '(as': 0.34; 'all.': 0.34; 'depend': 0.36; 'entry': 0.37; 'received:org': 0.37; 'subject:: ': 0.39; 'to:addr:python.org': 0.39; 'getting': 0.40; 'far': 0.40; 'being': 0.40; 'user': 0.40; 'order': 0.62; 'view': 0.65; 'here.': 0.66; 'order,': 0.73; 'ware': 0.91 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Terry Reedy Subject: Re: Dictionary sorting Date: Thu, 03 Nov 2011 17:36:25 -0400 References: <16245908.783.1320346014867.JavaMail.geo-discussion-forums@yqhd1> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: pool-74-109-121-73.phlapa.fios.verizon.net User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:6.0) Gecko/20110812 Thunderbird/6.0 In-Reply-To: <16245908.783.1320346014867.JavaMail.geo-discussion-forums@yqhd1> 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: 19 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1320356213 news.xs4all.nl 6850 [2001:888:2000:d::a6]:52795 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:15307 On 11/3/2011 2:46 PM, Scott Ware wrote: > Python newbie here. So, when creating dictionaries, I am noticing > that each time I print it out, that its not in the same order as when > I typed it in. They seem to be getting sorted somehow. No, the entries are not being sorted at all. > 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. If you want to keep the dict sorted by entry order (as far as the user view goes), use collections.OrderedDict. -- Terry Jan Reedy