If I have a python dictionary (or set, or some other kind of unordered container) and I call __str__
or __repr__
on it, which order of keys and/or values can I expect?
Of course, as the name "unordered container" states there is no particular order of contained elements. Yet, if the contained elements are printed in arbitrary order, is this arbitrary order at least persistent?
Will the string representation of the container always be the same (given I do not change anything about the container or its elements)? Or will the nth call to
__repr__
or__str__
at some point change the order of printed elements?What happens if I re-create the dictionary with the very same content (maybe on a different machine) will the order of printed elements still be the same as before?
EDIT: Why is this question marked as duplicate? I am not asking why the order is arbitrary. I ask whether string representations are persistent. Which might depend on more than just the underlying hash mechanism.