Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #41400

Just curious - I thought dict keys would maintain sequence

Path csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.005
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'none)': 0.07; 'python': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:keys': 0.09; 'subject:would': 0.09; 'dictionary,': 0.16; 'keys.': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'sequence.': 0.16; 'creates': 0.18; 'keys': 0.22; 'runs': 0.22; 'so.': 0.24; 'header:User-Agent:1': 0.26; 'appear': 0.26; 'see,': 0.27; 'header:X-Complaints-To:1': 0.28; 'attempting': 0.29; 'dictionary': 0.29; 'surprised': 0.29; 'to:addr:python-list': 0.33; 'version': 0.34; 'thanks': 0.34; 'received:org': 0.36; 'totally': 0.36; 'skip:p 20': 0.36; 'received:co.za': 0.37; 'received:za': 0.37; 'to:addr:python.org': 0.39; 'header:Received:5': 0.40; 'skip:n 10': 0.63; 'results': 0.65; 'received:41': 0.73; 'frank': 0.75; 'subject:thought': 0.84; 'subject:Just': 0.93
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Frank Millman <frank@chagford.com>
Subject Just curious - I thought dict keys would maintain sequence
Date Mon, 18 Mar 2013 09:26:19 +0200
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host 41-135-111-167.dsl.mweb.co.za
User-Agent Mozilla/5.0 (Windows NT 5.2; rv:14.0) Gecko/20120713 Thunderbird/14.0
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.3413.1363591587.2939.python-list@python.org> (permalink)
Lines 43
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1363591587 news.xs4all.nl 6976 [2001:888:2000:d::a6]:38647
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:41400

Show key headers only | View raw


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.

Thanks

Frank Millman


F:\>type test.py
test_list = [
     'ert', 'jhg', 'yer', 'nli', 'vrg',
     'qnh', 'kyh', 'cgj', 'lys', 'vyk',
     'dws', 'fuj', 'ghj', 'puy', 'brc',
     'dhy', 'jkl', 'gfd', 'jtf', 'dfp']
test_dict = dict([(x, None) for x in test_list])
print(test_dict.keys())

F:\>test.py
dict_keys(['ghj', 'qnh', 'lys', 'ert', 'jhg', 'dfp', 'vrg', 'dws', 
'jtf', 'puy',
  'yer', 'brc', 'kyh', 'jkl', 'gfd', 'nli', 'fuj', 'dhy', 'cgj', 'vyk'])

F:\>test.py
dict_keys(['vrg', 'dfp', 'brc', 'yer', 'nli', 'jhg', 'cgj', 'ert', 
'dws', 'gfd',
  'puy', 'vyk', 'ghj', 'jkl', 'jtf', 'kyh', 'qnh', 'fuj', 'dhy', 'lys'])

F:\>test.py
dict_keys(['yer', 'nli', 'brc', 'fuj', 'cgj', 'dfp', 'dhy', 'vrg', 
'jkl', 'jtf',
  'vyk', 'ghj', 'qnh', 'kyh', 'gfd', 'ert', 'dws', 'jhg', 'lys', 'puy'])

Python version is 3.3.0, win32.

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Just curious - I thought dict keys would maintain sequence Frank Millman <frank@chagford.com> - 2013-03-18 09:26 +0200

csiph-web