-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Guarantee consistent order of pairs, keys and values in Dicts #28196
Comments
I could do a PR myself. But first can someone confirm that this is guaranteed? |
IIUC there is currently no order guarantee, hence why it is not documented. This PR has an |
The question is about whether iterating pairs, keys and values will be consistent given that the dict has not been modified in between. That is the case and I have a hard time imagining a way violations that would be beneficial, so I can’t see any harm in guaranteeing it. @JeffBezanson? |
There are multiple ways to iterate a
Dict
. The functionskeys(dict)
andvalues(dict)
are guaranteed to return items in a consistent order, as stated in the docs (https://docs.julialang.org/en/latest/base/collections/#Base.keys):This is of course assuming that the
Dict
has not been modified in between. However it is not asserted thatfor (k,v) in dict ...
also iterates items in the same order askeys(dict)
andvalues(dict)
. If this is guaranteed, it should be mentioned in the docs.The text was updated successfully, but these errors were encountered: