joseleeph

Untitled

Dec 3rd, 2020
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 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['jackiie']} prints")
  20. # pythonic way of asking if a value is in the dictionary
  21. # you can treat it like an array where instead of the indices are numbers, the indices are words
  22. # key value pairs keys are strings
Advertisement
Add Comment
Please, Sign In to add comment