Assignment: CP1 - Data Structures and Files

22-23 - HHS - UW CSE163 INT DATA PROG A - T2
2023-01-10T20:00:42Z

Due: Jan 27, 2023 by 11:59pm

Overview

There are 10 problems total to implement (solve). You'll find details for each problem in the code's comments. Please read the code. There are 2 problems that are classroom activities; we will work on them together in class.

Each problem has instructions in the comments to help you along. Many will have a link to the web page with full, detailed instructions. Below you'll see some extra (perhaps redundant) instructions for 2 problems found in Lesson 6.

Lesson 4 Problems

fun_numbers

count_long_lines

count_unique_words

get_included_words

Lesson 5 Problems

get_set_of_words

count_words

area_codes

Lesson 6 Problems

most_frequent

shakiness_by_location

largest_magnitude

Lesson 6 Details

There is a dataset called earthquakes.csv. You do not need to worry about how to parse the data from the CSV format to the list of dictionaries. We implemented this functionality in cse163_utils.py and already wrote the code in the main method to call that function for the earthquakes file. You will use the parse method provided for you to create a list of dictionaries containing the data. You may want to open the file in Excel to examine is structure (columns and values).

There are 2 CSV problems (methods) for you to solve.

largest_magnitude

shakiness_by_location

You need to pass all unit tests.

Largest Magnitude

Write a function named largest_magnitude that takes a parameter data that stores this earthquakes dataset represented as a list of dictionaries as a parameter. It should return the name of the location that experienced the largest earthquake in the dataset. If there are no rows in the dataset, it should return None.

Shakiness By Location

We want you to write a function named shakiness_by_location that takes a parameter that represents the earthquakes dataset from the last problem in the list of dictionaries format. This function should return a dict that stores how “shaky” each location in the dataset is. To define what this means, the return value should be a dict whose keys are location names and whose values are the sum of all the earthquakes’ magnitudes that occurred at that location. If there are no earthquakes in the dataset, it should return an empty dict.

For example, suppose our dataset stored in a variable named data contained the following rows (only showing the name and magnitude columns since those are the only relevant ones).

[
    {'name': 'Seattle', 'magnitude': 4},
    {'name': 'Genovia', 'magnitude': 6},
    {'name': 'Seattle', 'magnitude': 3.5}
]

Then the call shakiness_by_location(data) would return:

{'Seattle': 7.5, 'Genovia': 6}

Overview

There are 10 problems total to implement (solve). You'll find details for each problem in the code's comments. Please read the code. There are 2 problems that are classroom activities; we will work on them together in class.

Each problem has instructions in the comments to help you along. Many will have a link to the web page with full, detailed instructions. Below you'll see some extra (perhaps redundant) instructions for 2 problems found in Lesson 6.

Lesson 4 Problems

fun_numbers

count_long_lines

count_unique_words

get_included_words

Lesson 5 Problems

get_set_of_words

count_words

area_codes

Lesson 6 Problems

most_frequent

shakiness_by_location

largest_magnitude

Lesson 6 Details

There is a dataset called earthquakes.csv. You do not need to worry about how to parse the data from the CSV format to the list of dictionaries. We implemented this functionality in cse163_utils.py and already wrote the code in the main method to call that function for the earthquakes file. You will use the parse method provided for you to create a list of dictionaries containing the data. You may want to open the file in Excel to examine is structure (columns and values).

There are 2 CSV problems (methods) for you to solve.

largest_magnitude

shakiness_by_location

You need to pass all unit tests.

Largest Magnitude

Write a function named largest_magnitude that takes a parameter data that stores this earthquakes dataset represented as a list of dictionaries as a parameter. It should return the name of the location that experienced the largest earthquake in the dataset. If there are no rows in the dataset, it should return None.

Shakiness By Location

We want you to write a function named shakiness_by_location that takes a parameter that represents the earthquakes dataset from the last problem in the list of dictionaries format. This function should return a dict that stores how “shaky” each location in the dataset is. To define what this means, the return value should be a dict whose keys are location names and whose values are the sum of all the earthquakes’ magnitudes that occurred at that location. If there are no earthquakes in the dataset, it should return an empty dict.

For example, suppose our dataset stored in a variable named data contained the following rows (only showing the name and magnitude columns since those are the only relevant ones).

[
    {'name': 'Seattle', 'magnitude': 4},
    {'name': 'Genovia', 'magnitude': 6},
    {'name': 'Seattle', 'magnitude': 3.5}
]

Then the call shakiness_by_location(data) would return:

{'Seattle': 7.5, 'Genovia': 6}