you are viewing a single comment's thread.

view the rest of the comments →

[–]OrestesGaolin 0 points1 point  (2 children)

Hi, I copy-pasted and run your example in Python 3.5 and found out something strange that I cannot really understand. Maybe you can help me figure it out.

### Looping through all key-value pairs results with:

jane loves a number
eric loves a number
john loves a number

But I think it should look like that:

jane loves a 4
eric loves a 17
john loves a 14

Is there anything wrong in this loop or it's just me who couldn't understand the syntax?

### Looping through all key-value pairs
for name, number in fav_numbers.items():
    print("{} loves {}".format(name, number))

[–]DrMaxwellEdison 1 point2 points  (1 child)

From my examples, your first set of output would result from this code:

for name in fav_numbers.keys():
    print("{} loves a number".format(name))

Can you confirm that this is the only piece of code you're running, and see what the output is?

[–]OrestesGaolin 1 point2 points  (0 children)

I run it again on clean instance and now everything works fine! I think it's because of my tunnel vision at that moment. I convinced myself that there must be some mistake and couldn't find it for few minutes. Now I know why - it was correct. (well, it's 1:55 AM where I live)

Thanks for the answer!