Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
# create an empty dictionary | |
empty_property = dict() | |
# create dictionary using a list of key-value tuples | |
job2 = dict([ | |
("title","Marketing & Business Development Manager"),("location","Mombasa"), | |
("job_type","Full Time"), | |
("employer","KUSCCO Limited (Kenya Union of Savings & Credit Co-operatives Limited)"), | |
("category","Marketing & Communications") | |
]) |
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
# Using keyword arguments | |
dict( | |
title="Marketing & Business Development Manager", | |
location="Mombasa",job_type="Full Time", | |
employer="KUSCCO Limited (Kenya Union of Savings & Credit Co-operatives Limited)", | |
category="Marketing & Communications" | |
) |
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
# Check existence of title | |
"title" in job2 # returns True | |
"salary" in job2 # returns False | |
# Using key indexing | |
job2["title"] # return 'Marketing & Business Development Manager' |
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
# Using get() method | |
job2.get("title") # return 'Marketing & Business Development Manager' | |
job2.get("salary") # return None | |
# Passing a second argument to get() | |
job2.get("salary", 5000) # return 5000 |
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
# Adding a new entry for salary using the index | |
job2["salary"] = 10000 | |
# Modifying the entry for job_type using the index | |
job2["job_type"] = "Part time" | |
# Modifying the salary entry using update | |
job2.update({"salary":20000}) | |
# Adding the available entry using update |
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
extra_info = { | |
"verified":True, | |
"qualification":"Undergraduate Degree", | |
"taxable":True} | |
# Merge extra_info with job2 | |
job2.update(extra_info) |
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
del job2["salary"] | |
del job2["available"] | |
print(job2) #return a dictionary without 'salary' and 'available' entries | |
job1.clear() | |
print(job1) #return an empty dictionary | |
del job1 | |
print(job1) # return NameError |
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(): |
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
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 |
OlderNewer