joseleeph

Untitled

Dec 3rd, 2020
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. from sys import exit
  2.  
  3. # a dictionary has keys and values, names and numbers in this case
  4. # could be words and definition
  5. people = {
  6. "Lucio": "617-868-8543",
  7. "Jackie": "617-876-9580",
  8. "Matthew": "617-864-2838",
  9. "Jacob": "617-519-3820",
  10. }
  11.  
  12. if "Jacob" in people:
  13. print(f"Found {people['Jacob']}") # will print the value that was associated with the string jacob
  14. exit(0)
  15. else:
  16. print("not found")
  17. for person in people: ## this does not work... ask reddit how i might print every item in dictionary
  18. print(person)
  19. print(" {people['jackie']} prints") # why won't this print? it's just a string
  20. print(f"{people['jackie']}") # this doesn't print anything as it does above
  21. # pythonic way of asking if a value is in the dictionary
  22. # you can treat it like an array where instead of the indices are numbers, the indices are words
  23. # key value pairs keys are strings
Advertisement
Add Comment
Please, Sign In to add comment