Collections.OrderedDict()

  • + 0 comments

    Since CPython 3.6, normal dict keep the insertion order. Since Python 3.7, it is a guaranteed language feature. So you can just check the version of Python and use a normal dict instead of an OrderedDict (or better here, a defaultdict) and it will work with all implementations of Python 3.7+. It works on Hackerrank for this exercise, both with a dict and a defaultdict.