RPeraltaJr
5/10/2020 - 4:02 PM

Iterate over Dictionaries

course = {'teacher': 'Ashley', 'title': 'Introducting Dictionaries', 'level': 'Beginner'}

# access both key and value (option #1)
for item in course:
  print(item) # returns only the key
  print(course[item]) # returns only the value
  
# access both key and value (option #2)
for key, value in course.items():
  print(key)
  print(value)
  
# access only keys
for key in course.keys():
  print(key) 
  
# access only values
for value in course.values():
  print(value)