I am trying to iterate over a dictionary (inside another dictionary specifically, but I don't think that part matters), and I'm unable to get the for loop to iterate over the values in the order that they were placed in. I would like to be able to take the first value of each dictionary. I thought that after python 3.6, dictionaries kept their order (here), but these wont stay in order.
This is what my dictionary looks like:
count_dict = {'dessert': Counter({'cake': 1}), 'vegetable': Counter({'carrots': 1, 'beet': 1}), 'grain': Counter({'wheat': 3, 'rice': 2, 'zantham': 1}), 'meat': Counter({'chicken': 2, 'pork': 1})}
This is my code that tried:
for it in count_dict:
for food in count_dict[it]:
out_dict[it] = food
return(out_dict)
I get:
{'dessert': 'cake', 'vegetable': 'beet', 'grain': 'rice', 'meat': 'chicken'}
but need to get the first value from each dictionary:
{'dessert': 'cake', 'vegetable': 'carrots', 'grain': 'wheat', 'meat': 'chicken'}
I looked for ever for an answer on Stack but couldn't find an answer. (sorry if the answers obvious, I'm kinda new to Python)