Question: Reducing the Data Load the contents of the JSON - formatted data file into a variable named city _ dicts _ Ist To create the
Reducing the Data
Load the contents of the JSONformatted data file into a variable named citydictsIst
To create the data structures required to produce the three bar charts you will need to reduce citydictsIst into three summary dictionaries:
murderbyregion
violentbyregion
nonviolentbyregion
To do so iterate over citydictsIst and create each respective dictionary using an accumulation pattern. The resulting dictionaries should be identical to this:
printmurderbyregion
printviolentbyregion
printnonviolentbyregion
'South': 'West': 'Northeast': 'Midwest':
South: 'West': 'Northeast: 'Midwest': South: 'West': 'Northeast': 'Midwest':
Create a function named accumcrime to make the three dictionaries shown above.
accum crime has three parameters:
Parameter
Description
unit
key upon which to accumulate ie Region or State
crime
crime eg Murder, VehicleTheft, etc. used to accumulate summary values for the specified unit
citydictslst
list containing dictionaries for each city, read from provided data
file
The accumcrime function should produce the summary dictionaries shown above when appropriate parameters are provided.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
