Skip to content

Instantly share code, notes, and snippets.

@ardenn
Created October 1, 2018 18:03
Show Gist options
  • Save ardenn/5821ab220bf47f5679f1f3b1d2f61a79 to your computer and use it in GitHub Desktop.
Save ardenn/5821ab220bf47f5679f1f3b1d2f61a79 to your computer and use it in GitHub Desktop.
Python Dictionaries Tutorial - Iteration
# Iterating through the dictionary itself
for x in job2:
print(x) # prints the keys of job2
# Using keys()
for key in job2.keys():
print(key) # prints the keys of job2
# Using values()
for val in job2.values():
print(val) # prints the values of job2
# Dictionary iteration use case
import csv
with open('jobs.csv','r') as csv_file:
reader = csv.DictReader(csv_file)
for job in reader:
# Using items()
for key,val in job.items():
# Apply any additional processing
print(key, val) #print the keys and values of each job
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment