CSE 163
CSVs and Lists of Dictionaries
Arpan Kapoor�Summer 2026��💭Icebreaker (discuss with neighbors): ‘
What is your favorite gloomy day activity? Add to our Slido!
#2348882
Announcements
#2348882
Dictionary Methods
dict() or {} | Makes an empty dictionary |
d[key] | Gets the value for k, KeyError if None |
d[key] = val | Assigns val as the value for key |
d.pop(key) | Removes key from this dictionary |
d.keys() | Returns a collection of the keys |
d.values() | Returns a collection of the values |
d.items() | Returns a collection of (key, value) tuples |
#2348882
Processing CSVs
#2348882
Processing CSVs
5
Name,Salary
Madrona,3
Ken,1
Ryan,3
[
{'Name': 'Madrona', 'Salary': 3},
]
#2348882
Processing CSVs
6
Name,Salary
Madrona,3
Ken,1
Ryan,3
[
{'Name': 'Madrona', 'Salary': 3},
{‘Name': 'Ken', 'Salary': 3},
]
#2348882
Processing CSVs
7
Name,Salary
Madrona,3
Ken,1
Ryan,3
[
{'Name': 'Madrona', 'Salary': 3},
{‘Name': 'Ken', 'Salary': 3},
{‘Name': 'Ryan’, 'Salary’: 3}
]
#2348882
Processing CSVs
8
Name,Salary
Madrona,3
Ken,1
Ryan,3
[
{'Name': 'Madrona', 'Salary': 3},
{‘Name': 'Ken', 'Salary': 3},
{‘Name': 'Ryan’, 'Salary’: 3}
]
0
1
2
0
1
2
#2348882
Be careful of the data types!
# data is a list containing dictionaries
tas = cse163_utils.parse('tas.csv')
# tas[0] is a dictionary
madrona = tas[0]
# madrona['Salary'] is an int
madrona['Salary']
# Also works without an intermediate variable
tas[0]['Salary']
# Doesn't work! List doesn't allow string indices
tas['Salary'][0]
#2348882
Lesson Recap
#2348882
Group Work: Best Practices
#2348882