What not add a new format verb instead?
[1] https://docs.python.org/3/whatsnew/3.6.html#whatsnew36-compa...
Early in Go's development, they intentionally randomized the iteration offset to make sure developers didn't become dependent on a behaviour they didn't want to be tied to.
You see this in Erlang also, where iteration order is deterministic (though not based on insertion order), but documentation makes sure to say iteration is arbitrary.
So, the answer to your question is that most people don't want their dictionaries implementation to be tied down due to this feature.
Except it worked so well in Python and PyPy that in Python 3.7 it was blessed into an official part of the language spec.
FWIW https://docs.python.org/3/whatsnew/3.7.html
> the insertion-order preservation nature of dict objects has been declared to be an official part of the Python language spec.
https://mail.python.org/pipermail/python-dev/2017-December/1...
There's a big difference between "iteration order is deterministic" and "iteration order is <very specific high-level behaviour>" even if the latter is a side-effect of an implementation details. In particular, iteration order being either insertion order or sorted are useful and sought-after properties, while other implementation-dependent deterministic orderings are mostly implicit dependencies and sources of bugs (not unlike e.g. the scheduling sequence of goroutines in Go).
fmt should only print, not manipulate the data it is asked to print.
I believe that the spec says that maps iterate over keys effectively at random and so that should be the result of any operation that iterates over keys.
`fmt` has always made things look prettier, that's part of what formatting is about.
You could equally argue that `fmt` should not round floats or pad numbers with zeros or spaces.
Really I have never seen print change the order of the data it is given (that's manipulating, indeed) for the sake of what seems to be laziness.
If there is a real need for sorted iteration then it should be external to print, possibly a new API of maps.
Eh? That's exactly the functionality they are announcing...
For printing purposes that means that it doesn't matter which order you print something out in. ANY order is equally correct. So you might as well choose the one that makes the most sense to human eyes, which is to print them out ordered alphabetically on the keys.
Just because the printing function is choosing alphabetical order to print things out in, it's not "manipulating" anything. Literally nothing about the map changes.
Clearly, I am not the one missing the point...
The order maps iterate is not the point. The point is that e.g. a 'print' function should print, not sort and change the order.
> just because the printing function is choosing alphabetical order to print things out in, it's not "manipulating" anything
Again, the printing function does not 'choose', it manipulates the date returned by sorting them.
My point is that, to follow good design principle, this sorted iteration should be a public API of maps.
The point is that a print should print in the order it is getting data.
Given that the order of keys in a map is not guaranteed, I also wouldn't consider rendering them in a fixed order as "manipulation". The order of the keys is undefined, unimportant, program-wise. So presenting them in a certain order implies meaning (presumably there is one, whether it be creation order, LRU, or physical-memory layout). But if you know the keys are sorted before being printed, then you can continue to assume you don't know the actual order, or to put it another way, you can continue to suspend your disbelief about whether the keys are truly "unordered" in the system.
But to get back to practical concerns, I'm genuinely curious what harm you see from presenting the unordered keys in a predictable order that allows humans to get more use from the particular formatting?