Before you turn this problem in, make sure everything runs as expected. First, restart the kernel (in the menubar, select Kernel$\rightarrow$Restart) and then run all cells (in the menubar, select Cell$\rightarrow$Run All).

Make sure you fill in any place that says YOUR CODE HERE or "YOUR ANSWER HERE", as well as your name and collaborators below:

In [ ]:
NAME = ""
COLLABORATORS = ""

In [ ]:
import os
import os.path

datadir = "publicdata"

topnamesDoL = {'year': [2018, 2018, 2017, 2017, 2016, 2016],
          'sex': ['Male', 'Female', 'Male',
                    'Female', 'Male', 'Female'],
          'name': ['Liam', 'Emma', 'Liam', 'Emma',
                     'Noah', 'Emma'],
          'count': [19837, 18688, 18798, 19800, 19117, 19496]}

topnamesLoL = [[2018, 'Male', 'Liam', 19837],
               [2018, 'Female', 'Emma', 18688],
               [2017, 'Male', 'Liam', 18798],
               [2017, 'Female', 'Emma', 19800],
               [2016, 'Male', 'Noah', 19117],
               [2016, 'Female', 'Emma', 19496]]
columns = ['year', 'sex', 'name', 'count']

Q1: Write a function

convertDoL2LoL(D)

that converts from a dictionary of lists representation in D to the equivalent list of lists representation, returning both the list of column names, as given by the keys of D, as well as a list of lists storing the data in the values of D. Note that, because we do not know the order of mappings in a dictionary, the order of fields in the column names, and the order of fields in the rows of the data set may not be apparent. But as long as all rows as well as the list of column names is consistent, the conversion is valid.

In [ ]:
# Solution cell

# YOUR CODE HERE
raise NotImplementedError()
    
In [ ]:
# Testing cell

convertDoL2LoL(topnamesDoL)

Q (TB): Write a function

convertLoL2DoL(columns, data)

that converts from a list of lists to a dictionary of lists D, which you return. Here, columns is a list of column names (which will become the keys in D), and data is a list of row lists.

In [ ]:
# Solution cell

# YOUR CODE HERE
raise NotImplementedError()
    
In [ ]:
# Testing cell

convertLoL2DoL(columns, topnamesLoL)