Skip to main content
4 events
when toggle format what by license comment
May 30, 2018 at 5:56 comment added 200_success Update: dict in Python 3.7 is guaranteed to preserve the key insertion order. In practice, this is also true of CPython 3.6.
Oct 1, 2017 at 5:07 comment added 200_success Python dictionaries do not guarantee any iteration order. To preserve the order, you need collections.OrderedDict. If you get the dict results in the same order as the original, that is by luck, not by design. (That is the reason why most_common() returns a list of pairs, rather than a dict.)
Oct 1, 2017 at 5:02 comment added SKN The Counter.most_common() method returns a list of tuples sorted from the most common to the least common, and I’ve just tried dict([('x', 10), ('y', 8), ('z', 6)]) returning {'x': 10, 'y': 8, 'z': 6}. As you see, the order isn’t scrambled. Am I missing something? Thanks for the advice on docstrings. I’ll look into the fileinput module.
Oct 1, 2017 at 2:28 history answered 200_success CC BY-SA 3.0