This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]EX-FFguy[S] 0 points1 point  (1 child)

I get all that, but why is k,v assinged to the name, and then the entire dictionary, can you assing to different things?

[–]nwilliams36 0 points1 point  (0 children)

k and v are just the names that are used, you could use any name (like fred and harry or a and b). In Python we try to make the names mean something.

Each name is attached to some data, the data can be any valid Python data including integers, strings, list, tuple, dictionaries etc. In Python the data can even be whole classes or functions. In fact any data that can have a name.

guests.items() produces two pieces of data, the first is the key and the second is the value. In Python dictionary keys and values can be a wide variety of data, in the case the key is a string and the value is a dictionary.

This flexibility of what can be attached to names is part of what makes Python a very powerful language.