Path: csiph.com!usenet.pasdenom.info!news.albasani.net!newsfeed.freenet.ag!news2.euro.net!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.032 X-Spam-Evidence: '*H*': 0.94; '*S*': 0.00; 'python': 0.09; 'subject:keys': 0.09; 'subject:would': 0.09; 'dictionary,': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'keys.': 0.16; 'sequence.': 0.16; 'utterly': 0.16; 'mon,': 0.16; 'wrote:': 0.17; 'creates': 0.18; 'versions': 0.20; 'keys': 0.22; 'runs': 0.22; 'so.': 0.24; 'header:In-Reply-To:1': 0.25; 'appear': 0.26; 'see,': 0.27; 'message-id:@mail.gmail.com': 0.27; 'there.': 0.28; 'attempting': 0.29; 'dictionary': 0.29; 'hash': 0.29; 'surprised': 0.29; 'on,': 0.30; 'defense': 0.33; 'to:addr:python- list': 0.33; 'likely': 0.33; 'received:google.com': 0.34; 'pm,': 0.35; 'something': 0.35; 'totally': 0.36; 'anything': 0.36; 'subject:: ': 0.38; 'object': 0.38; 'to:addr:python.org': 0.39; 'your': 0.60; 'most': 0.61; 'skip:n 10': 0.63; 'results': 0.65; 'frank': 0.75; '2013': 0.84; 'extent.': 0.84; 'subject:thought': 0.84; 'subject:Just': 0.93 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:content-type; bh=ivnBLnmEf2H7/DE/33eSy77zjjT3TIIZOf4t1y8XiEs=; b=P2eFJ4LChVJeztuW3BFWE5cwt7J8JH2l7xLVzwQFUEd7w/1YDtfdvBIPoQGpoutHxQ uRP/F9LcWxtfiBV1vvmmcptXxXfiE7YpjwbB9mqp6Aib53X4WXYo0z92xrmYj1y/9l+K QJgq9lII25UBOdjwJyoNEcfKSt0iOrV+Rg7D9TfhZTnFUveCwQvr6qBRlqDrA4w88rsa SO1MmeKGYFNAz9sRS52jqnnWXOAYYtZ+Tdg2IjWbRoBuQAJ0FMnt8MbnJ54xIivhkw3Y TaGhhBW1A+b1luGclR7jd7yht7llmBPAMIfBXalg+IKGdjDp14J3ZAy684HmKXu8KUpT numA== MIME-Version: 1.0 X-Received: by 10.58.253.161 with SMTP id ab1mr18448531ved.55.1363591893169; Mon, 18 Mar 2013 00:31:33 -0700 (PDT) In-Reply-To: References: Date: Mon, 18 Mar 2013 18:31:33 +1100 Subject: Re: Just curious - I thought dict keys would maintain sequence From: Chris Angelico To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 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: 1363591901 news.xs4all.nl 6883 [2001:888:2000:d::a6]:41462 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:41401 On Mon, Mar 18, 2013 at 6:26 PM, Frank Millman wrote: > Hi all > > I know that you cannot rely on the order of keys in a dictionary, and I am > not attempting to do so. > > Nevertheless, the following surprised me. A program creates a dictionary > with a known set of keys. I would have thought that multiple runs of the > program would return the keys in the same sequence. As you can see, the > results appear to be totally random. > > Just out of interest, I would appreciate an explanation. Mainly, it's just something you utterly cannot depend on, so it's allowed to vary based on the phase of the moon, the position of your hard drive platters, or anything else it likes. The hashing is actually randomized in recent versions of Python as a defense against a denial of service attack by generating hash collisions; that's most likely what you're seeing there. The dictionary object is not deterministic to that extent. :) ChrisA