Python Forum
not not working looping through a dictionary
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
not not working looping through a dictionary
#2
on line 10 you want to iterate over the list peoples, not over the keys of the dict.

peoples = ['jen', 'sarah', 'edward', 'phil', 'jeff', 'cara', 'ben', 'adam', 'larry']
favorite_languages = {
    'jen' : 'python',
    'sarah' : 'c',
    'edward' : 'ruby',
    'phil' : 'python',
    'jeff' : 'python',
    'cara' : 'none',
    }
for person in peoples:
    if person in favorite_languages:
        print("Thanks {} for taking the survey.".format(person.title()))
    else:
        print("{}, Please take the survey.".format(person.title()))
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Messages In This Thread
RE: not not working looping through a dictionary - by buran - Oct-04-2018, 01:35 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  looping a dictionary harmans14 1 2,199 Apr-11-2021, 08:48 PM
Last Post: bowlofred
  making list in looping a dictionary glennford49 9 3,636 Jun-25-2020, 03:23 PM
Last Post: ndc85430
  Looping through dictionary and comparing values with elements of a separate list. Mr_Keystrokes 5 3,956 Jun-22-2018, 03:08 PM
Last Post: wavic
  Looping issue, stops working JohnOsis 7 4,518 Apr-05-2018, 09:20 PM
Last Post: nilamo
  Changing dictionary values not working SnekLover123 5 4,058 Nov-01-2017, 05:39 PM
Last Post: metulburr

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020