Answer the question
In order to leave comments, you need to log in
How is the value retrieved from the dictionary?
Hello, I'm learning Python by book and got to the paragraph about a dictionary and iterating over it.
The author provides the following code:
favorite_languages = {
'jen': 'python',
'sarah': 'c',
'edward': 'ruby',
'phil': 'python',
}
friends = ['phil', 'sarah']
for name in favorite_languages.keys():
print(name.title())
if name in friends:
language = favorite_languages[name].title()
print(f"\t{name.title()}, I see you love {language}!")
Jen
Sarah
Sarah, I see you love C!
Edward
Phil
Phil, I see you love Python!
language = favorite_languages[name].title()
Answer the question
In order to leave comments, you need to log in
Previously there was a line
This line runs through all the keys in the dictionary and writes each of them to the name variable.
String
Means that the value of the key stored in the variable will be entered into the variable .
And so it would be desirable for you to familiarize yourself with the basics of the Python language
for name in favorite_languages.keys():
language = favorite_languages[name].title()
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question