Created
October 1, 2018 18:03
-
-
Save ardenn/5821ab220bf47f5679f1f3b1d2f61a79 to your computer and use it in GitHub Desktop.
Python Dictionaries Tutorial - Iteration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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