ewe
ewe

Reputation: 159

Checking for loop and if conditional, yet it doesn't print string

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'

Upvotes: 1

Views: 17

Answers (1)

Md Johirul Islam
Md Johirul Islam

Reputation: 5162

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.

Upvotes: 2

Related Questions