I rely on it, because I generally think new features should be used until they are well known. Until then, it would be nice to leave a comment for your colleagues such as
for k in my_dict:
# NOTE: relies on deterministic 3.7+ key ordering
and also to enforce that the project requires Python 3.7+.
On the other hand, I can see the argument for using a collections.OrderedDict
even if you just need the insertion-ordering because it is more explicit and clear to everybody.
Unfortunately, OrderedDict
is in a bit of an awkward state now. Since 3.7+, regular dicts provide its most prominent feature (insertion-ordering), but you can't just port over its lesser used methods (such as move_to_end
) to regular dicts and remove OrderedDict
from collections
, because OrdereDict
also takes the insertion-order into account for equality checks.
It's also weird to me that sets in 3.7+ don't provide insertion-ordering, even though I often think of dicts as sets of keys with associated values.
Honestly as I am writing this I'm kind of talking myself out of relying on dict
insertion-ordering ...