I have a dict that looks like this:
{1: [(7.8121826300806522e-06, 0.0027950172807843614),
(4.8435532306500046e-05, 0.006959395541691121),
(4.6873095780483916e-06, 0.002165014458884123),
(2.9686293994306483e-05, 0.005728026341619567),
...
and so on. However, when I pass this dict to a function where I do the following:
for key, vals in dic.items():
for i in range(len(vals)):
mean, std = vals[i]
print(mean, std)
the values some out in a completely different order:
0.194110864246 0.48917376306916205
0.00532478368066 0.07417999717478747
0.00590132275876 0.07746526118007628
0.192434369854 0.447194389625775
0.0230381265761 0.17699968340608854
0.00160774718527 0.048076851436196597
0.0394265232975 0.19895854591008688
5.93725879886e-05 0.00790531061606315
However, if I take that block of code out of the function and run it on the dic before passing it into a function it works as expected, printing in the same order that shown at the top of the post.
My questions are essentially.... why? how do I fix this behavior? Is there a better way to do this?
Edit: This is not a duplicate of Python dictionary, how to keep keys/values in same order as declared?
^ the Order of my keys do not matter. The "completely different order" of values I have in the post are the values that print, in order, for the list in key 1. Which is why it is weird, as it is a different order.
For example:
(7.8121826300806522e-06, 0.0027950172807843614)
Might end up printing out as the 11th item or so, rather than the first