1

For this code, I predicted that it would result in 'Rachel likes the languages 'Python', 'Javascript', 'HTML/CSS'' and 'ye', I got the first part but not the second part. Doesn't the code check each item in people list, and if that person is equal to the key of the fav_lang dictionary, it will print 'ye'?

fav_lang = {
 'Rachel':['Python','Javascript','HTML/CSS'],
}
for name, language in fav_lang.items():
 print(name, 'likes the languages', str(language).replace('[','',1).replace(']',''))
people = ['Rachel','Hannah','Safia','Ilda']
for peeps in people:
 if peeps == fav_lang.keys():
 print('ye')

gives the output:

Rachel likes the languages 'Python', 'Javascript', 'HTML/CSS'
asked Jun 16, 2020 at 18:16
1
  • change if peeps == fav_lang.keys(): to if peeps in fav_lang: Commented Jun 16, 2020 at 18:21

1 Answer 1

2

Change the following part:

for peeps in people:
 if peeps == fav_lang.keys():
 print('ye')

To:

for peeps in people:
 if peeps in fav_lang.keys():
 print('ye')

Because fav_lang.keys() returns a list.

answered Jun 16, 2020 at 18:19
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.