1 of 5

CSE 163

CSVs and Lists of Dictionaries

��Hunter Schafer

Questions During Class? sli.do

  • Entry code: 163

🎵Music: Dr. Dog

2 of 5

This Time

  • Dictionary Methods
    • How to loop over dictionary
  • CSVs
  • List of Dictionaries

Last Time

  • List Comprehensions
  • Tuple
  • Sets
  • Dictionaries

2

3 of 5

Dictionary Methods

  • Dictionary Methods

3

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

4 of 5

Processing CSVs

  • Well structured so they are easy to parse!
  • Not clear how to represent since we need info on rows and cols. Have to use multiple data structures!

  • We will use a list of dictionaries to store this information

4

Name,Salary

Flora,3

Ken,1

Ryan,3

[

{'Name': 'Flora', 'Salary': 3},

{'Name': 'Ken', 'Salary': 1},

{'Name': ‘Ryan’, 'Salary': 3}

]

5 of 5

Group Work:

Best Practices

When you first working with this group:

  • Turn on your mic / camera or introduce yourself in chat
    • We prefer mic/camera if available to encourage sense of human interaction :)
  • Share your name + where in the world you’re calling in from!
  • Elect one person to “drive” and share their screen for reference

Tips:

  • Starts with making sure everyone agrees to work on the same problem
  • Make sure everyone gets a chance to contribute!
  • Ask if everyone agrees and periodically ask each other questions!
  • Call TAs over for help if you need any!

5