Equivalence of dictionary keys?

Blair Hall b.hall at irl.cri.nz
Mon Dec 1 22:22:52 EST 2003


I would like to determine whether two dictionaries have the
same set of keys. Can anyone tell me if I HAVE to sort
the key sequences as in this code snippet:

    # d1, d2 already created
    k1 = d1.keys()
    k1.sort()
    k2 = d2.keys()
    k2.sort()

    # are the keys the same?
    same = (k1 == k2)

I am guessing that two dictionaries with the same keys
will sort them in the same order but is this true?





More information about the Python-list mailing list