Equivalence of dictionary keys?

Emile van Sebille emile at fenx.com
Tue Dec 2 08:33:12 EST 2003


Duncan Booth:
> Blair Hall:
> > I am guessing that two dictionaries with the same keys
> > will sort them in the same order but is this true?
>
> Here's a simple counter-example using not two but one dictionary.
Just
> manipulating a dictionary can change the order of the keys:
>

Borrowing your jumble keys example, you can also use sets

d = {'a':1, 'b': 2, 'c': 3}
c = {'a':1, 'b': 2, 'c': 3}
for i in range(100): d[i] = i

for i in range(100): del d[i]

a = d.keys()
b = c.keys()

import sets
print sets.Set(a) == sets.Set(b)

--

Emile van Sebille
emile at fenx.com





More information about the Python-list mailing list