Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!feeder.erje.net!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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'shortcut': 0.09; 'subject:keys': 0.09; 'subject:same': 0.09; 'dictionaries': 0.16; 'from:addr:behnel.de': 0.16; 'from:addr:stefan_ml': 0.16; 'from:name:stefan behnel': 0.16; 'message-id:@dough.gmane.org': 0.16; 'order?': 0.16; 'received:80.91.229.3': 0.16; 'received:mnet-online.de': 0.16; 'received:plane.gmane.org': 0.16; 'should.': 0.16; 'subject:values': 0.16; 'stefan': 0.17; 'obviously': 0.18; 'code.': 0.20; "i'd": 0.22; 'header:In-Reply-To:1': 0.25; 'header :User-Agent:1': 0.26; 'question': 0.27; 'i.e.': 0.27; 'header:X -Complaints-To:1': 0.28; "i'm": 0.29; 'curious': 0.33; 'to:addr :python-list': 0.33; 'subject:?': 0.35; 'received:org': 0.36; 'subject:: ': 0.38; 'mean': 0.38; 'to:addr:python.org': 0.39; 'header:Received:5': 0.40; 'think': 0.40; 'necessarily': 0.63; 'received:93': 0.72; 'special': 0.73 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Stefan Behnel Subject: Re: dict: keys() and values() order guaranteed to be same? Date: Mon, 23 Jul 2012 13:43:14 +0200 References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: ppp-93-104-24-69.dynamic.mnet-online.de User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:14.0) Gecko/20120714 Thunderbird/14.0 In-Reply-To: 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: 1343043813 news.xs4all.nl 6948 [2001:888:2000:d::a6]:35840 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:25852 Henrik Faber, 23.07.2012 13:23: > I have a question of which I'm unsure if the specification guarantees > it. With an arbitrary dictionaty d, are d.keys() and d.values() > guaraneed to be in the same order? I.e. what I mean is: > > # For all dictionaries d: > assert({ list(d.keys())[i]: list(d.values())[i] for i in range(len(d)) } > == d) > > I'm curious if it's allowed because in a special case it would make for > a nice shortcut and clean code. I think however that the implementation > may chose not to have them in the same order necessarily -- then I'd > obviously avoid relying on it. You should. Stefan