There are multiple ways to iterate a Dict. The functions keys(dict) and values(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):
But keys(a) and values(a) both iterate a and return the elements in the same order.
This is of course assuming that the Dict has not been modified in between. However it is not asserted that for (k,v) in dict ... also iterates items in the same order as keys(dict) and values(dict). If this is guaranteed, it should be mentioned in the docs.
I could do a PR myself. But first can someone confirm that this is guaranteed?
Also, in what section of the docs should this clarification go?
IIUC there is currently no order guarantee, hence why it is not documented. This PR has an OrderedDict that was considered for a little while to become the default #10116, but I believe the change was not made because we don't want to be limited by that choice in the future.
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鈥檛 see any harm in guaranteeing it. @jeffbezanson?
Most helpful comment
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鈥檛 see any harm in guaranteeing it. @jeffbezanson?