Skip to content

Instantly share code, notes, and snippets.

@ardenn
Created October 1, 2018 18:05
Show Gist options
  • Save ardenn/97689589533220c336bad5ac0cfd65f1 to your computer and use it in GitHub Desktop.
Save ardenn/97689589533220c336bad5ac0cfd65f1 to your computer and use it in GitHub Desktop.
Python Dictionaries Tutorial - sorting
with open('jobs.csv','r') as csv_file:
reader = csv.DictReader(csv_file)
for job in reader:
# Using sorted() to sort a dictionary's items on the keys
for key,val in sorted(job.items(),key=lambda item:item[0]):
# 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