I cannot find anything published, but I believe that this logic can justify the behavior:
If you have two dictionaries, d1 and d2, you expect key comparison to check if they have the same keys, right?
def compare_dict_keys(d1, d2): d1.keys() == d2.keys()
This function should behave the same for all types of dictionaries (and OrderedDict is a dict type). It would be wrong if such a function started to return False just because d1 and d2 are sorted.
In other words, they should all evaluate the same thing (and they do it):
>>> {1:2, 3:4}.keys() == {3:4, 1:2}.keys() True >>> {1:2, 3:4}.keys() == OrderedDict([(3,4),(1,2)]).keys() True >>> OrderedDict([(1,2),(3,4)]).keys() == OrderedDict([(3,4),(1,2)]).keys() True
But OrderedDict is specal, isn't it?
What OrderedDict offers you is a guarantee of the order when you OrderedDict over it. The same guarantee exists for OrderedDict.keys() , but without breaking compatibility with dict .
zvone Dec 16 '15 at 20:16 2015-12-16 20:16
source share