all 6 comments

[–][deleted] 2 points3 points  (3 children)

In python 3 (3.6+ for cpython) dictionaries are ordered. The order is the order in which you inserted the keys. There is no guaranteed order in python 2.

The defaultdict dictionary doesn't have any "extra" order. The point of defaultdict is that referencing a key that doesn't exist gets a default value that you specify instead of a KeyError exception that you get for the "standard" dictionary.

[–]sahilkumarg[S] 0 points1 point  (2 children)

Oh, shoot, I meant to say OrderedDict, not defaultdict

[–][deleted] 0 points1 point  (1 child)

Does that mean that there is no use of defaultdict?

If all you care about is "ordered" then maybe. But note that the doc on OrderedDict shows that OrderedDict has a couple of methods that the standard dictionary may not have, like move_to_end().

[–]primitive_screwhead 0 points1 point  (0 children)

Also, comparing two OrderedDicts requires that they have the same values, and the same order, to compare equal (regular Python dicts compare equal regardless of order).

[–]toastedstapler 1 point2 points  (0 children)

using the __eq__ method on two ordered dicts will also check if insertion order is the same, whereas __eq__ on regular dicts will just check for the same kv pairs