473,503 Members | 1,643 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

The Order Of Dictionary Entries

I am aware that dictionary order is not guaranteed. But I ran into
something puzzling today. I filled a dictionary dynamically as a
program ran. Up to a certain point, the key order was the order
in which things were added. However, at some point, the dictionary
appeared to reorder its contents in some non-deterministic way - in
fact, it looked like it was putting all the uppercase keys first,
followed by lowercase keys.

I'm just curious, just what _is_ the approach used for ordering
dictionary keys?

(This was confirmed on both Unix and Win32, BTW).
--
----------------------------------------------------------------------------
Tim Daneliuk tu****@tundraware.com
PGP Key: http://www.tundraware.com/PGP/

Jul 18 '05 #1
2 2756
In article <in*************@eskimo.tundraware.com>,
Tim Daneliuk <tu****@tundraware.com> wrote:

I am aware that dictionary order is not guaranteed. But I ran into
something puzzling today. I filled a dictionary dynamically as a
program ran. Up to a certain point, the key order was the order
in which things were added. However, at some point, the dictionary
appeared to reorder its contents in some non-deterministic way - in
fact, it looked like it was putting all the uppercase keys first,
followed by lowercase keys.

I'm just curious, just what _is_ the approach used for ordering
dictionary keys?


Use the source, Luke. See Objects/dictobject.c

Hint: dicts are based on hashing.
--
Aahz (aa**@pythoncraft.com) <*> http://www.pythoncraft.com/

"Do not taunt happy fun for loops. Do not change lists you are looping over."
--Remco Gerlich, comp.lang.python
Jul 18 '05 #2

"Tim Daneliuk" <tu****@tundraware.com> wrote in message
news:in*************@eskimo.tundraware.com...
I am aware that dictionary order is not guaranteed. But I ran into
something puzzling today. I filled a dictionary dynamically as a
program ran. Up to a certain point, the key order was the order
in which things were added.


I am rather certain that this was an accident dependent on you adding the
keys in the order in which they were going to displayed. Try adding the
items in a different order and the display order should not change much if
at all. Example:
{1:1, 2:2} {1: 1, 2: 2} {2:2, 1:1}

{1: 1, 2: 2}

Terry J. Reedy


Jul 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2240
by: Microskills | last post by:
I am a new VB.NET programmer. I am writing a dictionary program with a Dictionary file has over 60000 entries. When user starts typing a word in the searchbox, I want to show words that start with...
38
10118
by: ssg31415926 | last post by:
I need to compare two string arrays defined as string such that the two arrays are equal if the contents of the two are the same, where order doesn't matter and every element must be unique. ...
5
21562
by: randy1200 | last post by:
I have the following: Dictionary<object, stringd = new Dictionary<object, string>(); I can add entries to the dictionary, and I can loop through the entries I've added to the Dictionary. This...
5
3831
by: Jon Smirl | last post by:
Is there some way to tell a dictionary object that I am going to load 1M objects into it and have it pre-allocate enought slots to hold all of the entries? Thus avoiding many thousand memory...
8
13271
by: Brian L. Troutwine | last post by:
I've got a problem that I can't seem to get my head around and hoped somebody might help me out a bit: I've got a dictionary, A, that is arbitarily large and may contains ints, None and more...
1
8016
by: O.B. | last post by:
I have an application that throws System.OutOfMemoryException when the application has only allocated 1.3GB of RAM (according to the Task Manager). I've repeated the operation several times and...
14
28274
by: erikcw | last post by:
Hi, I'm trying to turn o list of objects into a dictionary using a list comprehension. Something like entries = {} = d.id] for d in links]
8
7956
by: Bob Altman | last post by:
Hi all, I'm trying to do something that should be really easy, but I can't think of an obvious way to do it. I have a dictionary whose value is a "value type" (as opposed to a reference type --...
10
23704
by: orsula | last post by:
Hi Guys, I have a class A composed of several string and int members. I would like to manage a huge amount (several thousands) of A objects in a dictionary where each object has its unique key....
0
7084
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7278
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6991
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5578
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5013
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4672
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1512
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
736
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
380
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.