Question

Write a function crimes_by_code(code,dict) that takes an integer value code and a dictionary dict containing the...

Write a function crimes_by_code(code,dict) that takes an integer value code and a dictionary dict containing the statistics in the crime codes as arguments. This function returns a list of all the crimes with the given code that have occurred in the database. See the sample output for an example.

Sample run:

crimes_by_code(110, dict) returns [['Theft of Vehicle', '2005', '2', '12', '22', '30', '', 'VictoriaFraserview', '495178', '5452000'], ['Theft of Vehicle', '2003', '6', '5', '17', '0', '10XX ALBERNI ST', 'West End', '491059.4824', '5459122.418'], ['Theft of Vehicle', '2003', '9', '26', '8', '30', '10XX ALBERNI ST', 'West End', '491059.4824', '5459122.418'], ['Theft of Vehicle', '2004', '7', '24', '11', '15', '10XX ALBERNI ST', 'West End', '491059.4824', '5459122.418'], ['Theft of Vehicle', '2004', '8', '24', Page 4 of 7 '21', '0', '10XX ALBERNI ST', 'West End', '491059.4824', '5459122.418'],…]

THE LANGUAGE IS PYTHON

THAT IS WHAT THEY GAVE ME AS A QUESTION

0 0
Add a comment Improve this question Transcribed image text
Answer #1

def crimes_by_code(code,dict):
for d in dict: #iterate through dict
for key in d: #for each element
if key==code: #if key matches with the code
print(d[key]) #print it
print("")

#this is the database containg record
dict = ({101:['Theft of Vehicle', '2005', '2', '12', '22', '30', '', 'VictoriaFraserview', '495178', '5452000']},
{101:['Theft of Vehicle', '2003', '6', '5', '17', '0', '10XX ALBERNI ST', 'West End', '491059.4824', '5459122.418']},
{101:['Theft of Vehicle', '2003', '9', '26', '8', '30', '10XX ALBERNI ST', 'West End', '491059.4824', '5459122.418']},
{101: ['Theft of Vehicle', '2004', '7', '24', '11', '15', '10XX ALBERNI ST', 'West End', '491059.4824', '5459122.418']},
{101:['Theft of Vehicle', '2004', '8', '24', 'Page 4 of 7 21', '0', '10XX ALBERNI ST', 'West End', '491059.4824', '5459122.418']},
{102:['Theft of Vehicle', '2005', '2', '12', '22', '30', '', 'VictoriaFraserview', '495178', '5452000']},
{ 102:['Theft of Vehicle', '2003', '6', '5', '17', '0', '10XX ALBERNI ST', 'West End', '491059.4824', '5459122.418']},
{105:['Theft of Vehicle', '2003', '9', '26', '8', '30', '10XX ALBERNI ST', 'West End', '491059.4824', '5459122.418']},
{107: ['Theft of Vehicle', '2004', '7', '24', '11', '15', '10XX ALBERNI ST', 'West End', '491059.4824', '5459122.418']},
)
#driver program to test
crimes_by_code(101,dict)

output

['Theft of Vehicle', '2005', '2', '12', '22', '30', '', 'VictoriaFraserview', '495178', '5452000']

['Theft of Vehicle', '2003', '6', '5', '17', '0', '10XX ALBERNI ST', 'West End', '491059.4824', '5459122.418']

['Theft of Vehicle', '2003', '9', '26', '8', '30', '10XX ALBERNI ST', 'West End', '491059.4824', '5459122.418']

['Theft of Vehicle', '2004', '7', '24', '11', '15', '10XX ALBERNI ST', 'West End', '491059.4824', '5459122.418']

['Theft of Vehicle', '2004', '8', '24', 'Page 4 of 7 21', '0', '10XX ALBERNI ST', 'West End', '491059.4824', '5459122.418']

Add a comment
Know the answer?
Add Answer to:
Write a function crimes_by_code(code,dict) that takes an integer value code and a dictionary dict containing the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a function called filter_crime_stats(stats,param,x,y) that takes a 2D list of crime stats, a string argument...

    Write a function called filter_crime_stats(stats,param,x,y) that takes a 2D list of crime stats, a string argument param from the set {YEAR, MONTH, DAY}, an integer start value x and an integer end value y as arguments, and returns the 2D list of crime stats containing the crime type, year, month, day, and neighbourhood of all crimes reported between the start value and the end value of the {YEAR/MONTH/DAY}. The value of param is not case sensitive. For example, Year, YEAR,...

  • Write a function named "loadStateDict(filename) that takes a filename and returns a dictionary of 2-character state...

    Write a function named "loadStateDict(filename) that takes a filename and returns a dictionary of 2-character state codes and state names. The file has four columns and they are separated by commas. The first column is the state full name and the second column is the state code. You don't have to worry about column 3 & 4. You should eliminate any row that is without a state code. Save the two columns into a dictionary with key = state code...

  • can someone please help me write a python code for this urgently, asap Question: Write a Python function, minmp,...

    can someone please help me write a python code for this urgently, asap Question: Write a Python function, minmp, that is passed a file name and a metal alloy's formula unit structure*". The file will contain metal elements and their properties. The function will return a tuple of the element from the formula with the lowest melting point and that melting point Write a second function, molform, that will be called by the first function, to take the metal alloy's...

  • Problem 1 (Reading Statistics) Write a function called read_stats(filename) that takes a csv (comma separated values)...

    Problem 1 (Reading Statistics) Write a function called read_stats(filename) that takes a csv (comma separated values) filename as an argument and returns a 2D list containing the statistics in that file. The returned list should contain lists of stats for each crime reported and should not include the header line from the file. The file crime_in_vancouver.csv (included in the folder) has the following structure: • The first row provides headers for each column • Each subsequent row represents the stats...

  • In problem 3, you will write a function, findvertically (), which will determine whether or not...

    In problem 3, you will write a function, findvertically (), which will determine whether or not a given word exists in a word search puzzle vertically. In word search puzzles, words can be written upwards or downwards. For example, "BEAK" appears at [1] [3] written downwards, while "BET" appears at [2] [2] written upwards: [["C", "A", "T", "X", "R"], ["D", "T", "E", "B", "L"], ["A" "R" "B", "E", "Z"], ["X", "O", "E", "A", "U"], ["J", "S", "O", "K", "W"]] Your...

  • python program do not use dictionary, list only Complete the program found in assignment4.py. You may...

    python program do not use dictionary, list only Complete the program found in assignment4.py. You may not change any provided code. You may only complete the sections labeled: #YOUR CODE HERE Write a program that does the following. Reads the contents of Text from the include file, input.txt Create a dictionary of key-value pairs called index.txt Key: This represents the individual word Value: This is a list of the line number from Text where Key appeared Example: If the word...

  • Help with Data Science python notebook, Question 1 Create a function called vowel_parse() that takes a...

    Help with Data Science python notebook, Question 1 Create a function called vowel_parse() that takes a single string as input. This string is the name of the input directory. It returns a dictionary. This dictionary has keys that are the names of the individual input files. The dictionary values are the number of words in that file that have adjacent vowels ('aa', 'ae', 'oo', 'ia', etc.). Use a regular expression to find these, do not hard code every possible combination...

  • Please help we are suppose to explain what the C code does. This is the electronics database (6 pts) This problem is...

    Please help we are suppose to explain what the C code does. This is the electronics database (6 pts) This problem is based on Electronics database. Add some annotations to the following table to explain what the C program is doing in detail. Note that "void" is how C declares a function that does not return anything. You are expected to generalize or research svntaxes not mentioned in the lecture C Program Annotation void newPCproduct EXEC SQL BEGIN DECLARE SECTION;...

  • Python Pandas, Series and DataFrame Question (NO Loops, No If Statements, No List Comprehensions) The file...

    Python Pandas, Series and DataFrame Question (NO Loops, No If Statements, No List Comprehensions) The file bank.csv contains data about bank customers. The last column ('Personal Loan') indicates whether or not the customer was approved for a personal loan or not. Write a function named loan_by_zip that accepts 3 parameters: a file name, a minimum number of records, and a percentage approval rate. The function should return a DataFrame of those zip codes for which we meet the minimum number...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT