Here is a basic question for you awesome folks out there. I'm a fairly new person to coding and when I saw this code, I just couldn't figure it out. Here's the question: Why is profile[key] = value
in that specific loop? It seems like this code is making the dictionary key
into a value
which doesn't make sense in my head, any explanation would be great! The code:
def build_profile(first, last, **user_info):
"""Build a dictionary containing everything we know about a user"""
profile = {}
profile["first_name"] = first
profile["last_name"] = last
for key, value in user_info.items():
profile[key] = value # Why is this converting the key of the dictionary into a value?
return profile
user_profile = build_profile("albert", "einstein",
location="princeton",
field="physics")
print(user_profile)
P.S. This is on page 153 of "Python Crash Course"βIt gives an explanation but I just don't understand it, sorry.