We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
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.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Collections.OrderedDict()
You are viewing a single comment's thread. Return to all 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 normaldict
instead of an OrderedDict (or better here, adefaultdict
) and it will work with all implementations of Python 3.7+. It works on Hackerrank for this exercise, both with adict
and adefaultdict
.