Question

list_descriptions Define a function named list_descriptions with one parameter. This parameter will be a list of...

list_descriptions

Define a function named list_descriptions with one parameter. This parameter will be a list of dictionaries (the data). This function must return a list of strings. For each dictionary in the parameter, you will need the value it associates with the key 'tow_description'. If the accumulator list does not contain that tow description, you should add it to the accumulator list. After processing the list of dictionaries, the accumulator list's entries will be the values associated with the key 'tow_description' but without any duplicates. You SHOULD assume that all dictionaries in the parameter will have 'tow_description' as a key.

Sample function call: list_descriptions(data)

DATA IS DEFINED BELOW

data = [ {'unique_key': '201209064DPE', 'tow_date': '2012-09-06T00:00:00.000', 'agency': 'DPE', 'vehicle_year': 0, 'vehicle_make': 'MINI', 'tow_location': 'MAIN/CUSTER', 'city': 'Buffalo', 'state': 'NY', 'zip': '14214', 'tow_reason': 'AI', 'tow_description': 'ACCIDENT', 'location_1': "{'latitude': '42.950029001582', 'longitude': '-78.827175001441'}", 'latitude': 42.95002900158201, 'longitude': -78.827175001441, 'council_district': 'UNIVERSITY', 'police_district': 'District E', 'census_tract': '47', 'census_block_group': '5', 'census_block': '5003', 'neighborhood': 'UNKNOWN'},

{'unique_key': '200801247RON', 'tow_date': '2008-01-24T00:00:00.000', 'agency': 'RON', 'vehicle_year': 1995, 'vehicle_make': 'CHEV', 'license_state': 'NY', 'tow_location': '191 14TH', 'city': 'Buffalo', 'state': 'NY', 'zip': '14213', 'tow_reason': 'IP', 'tow_description': 'ILLEGALLY PARKED', 'location_1': "{'latitude': '42.906118854478', 'longitude': '-78.886454771174'}", 'latitude': 42.90611885447759, 'longitude': -78.88645477117358, 'council_district': 'NIAGARA', 'police_district': 'District B', 'census_tract': '69.02', 'census_block_group': '1', 'census_block': '1004', 'neighborhood': 'UNKNOWN'},

{'unique_key': '201308292RIV', 'tow_date': '2013-08-29T00:00:00.000', 'agency': 'RIV', 'vehicle_year': 2000, 'vehicle_make': 'BUIC', 'license_state': 'NY', 'tow_location': '98 GREENWOOD', 'city': 'Buffalo', 'state': 'NY', 'zip': '14213', 'tow_reason': 'IP', 'tow_description': 'ILLEGALLY PARKED', 'location_1': "{'latitude': '42.92264365562', 'longitude': '-78.888887800432'}", 'latitude': 42.922643655619744, 'longitude': -78.88888780043183, 'council_district': 'NIAGARA', 'police_district': 'District D', 'census_tract': '171', 'census_block_group': '3', 'census_block': '3004', 'neighborhood': 'UNKNOWN'},

{'unique_key': '2010040512DPE', 'tow_date': '2010-04-05T00:00:00.000', 'agency': 'DPE', 'vehicle_year': 1998, 'vehicle_make': 'CHEV', 'license_state': 'NY', 'tow_location': 'SMITH/CLINTON', 'city': 'Buffalo', 'state': 'NY', 'zip': '14210', 'tow_reason': 'IL', 'tow_description': 'ILLEGAL VEHICLE', 'location_1': "{'latitude': '42.880136970577', 'longitude': '-78.844075992214'}", 'latitude': 42.88013697057658, 'longitude': -78.84407599221383, 'council_district': 'FILLMORE', 'police_district': 'District C', 'census_tract': '15', 'census_block_group': '1', 'census_block': '1029', 'neighborhood': 'UNKNOWN'},

{'unique_key': '201006024RIV', 'tow_date': '2010-06-02T00:00:00.000', 'agency': 'RIV', 'vehicle_year': 0, 'vehicle_make': 'HOND', 'license_state': 'ON', 'tow_location': '26 REDMOND', 'city': 'Buffalo', 'state': 'NY', 'zip': '14216', 'tow_reason': 'IP', 'tow_description': 'ILLEGALLY PARKED', 'location_1': "{'latitude': '42.956679013187', 'longitude': '-78.848677111783'}", 'latitude': 42.95667901318747, 'longitude': -78.84867711178318, 'council_district': 'DELAWARE', 'police_district': 'District D', 'census_tract': '51', 'census_block_group': '1', 'census_block': '1004', 'neighborhood': 'UNKNOWN'},

{'unique_key': '201203169RIV', 'tow_date': '2012-03-16T00:00:00.000', 'agency': 'RIV', 'vehicle_year': 97, 'vehicle_make': 'CHEV', 'license_state': 'NY', 'tow_location': '178 CRESCENT', 'city': 'Buffalo', 'state': 'NY', 'zip': '14214', 'tow_reason': 'IP', 'tow_description': 'ILLEGALLY PARKED', 'location_1': "{'latitude': '42.932852585189', 'longitude': '-78.848168535448'}", 'latitude': 42.932852585189245, 'longitude': -78.84816853544807, 'council_district': 'DELAWARE', 'police_district': 'District D', 'census_tract': '52.01', 'census_block_group': '4', 'census_block': '4005', 'neighborhood': 'UNKNOWN'},

{'unique_key': '201208114SBA', 'tow_date': '2012-08-11T00:00:00.000', 'agency': 'SBA', 'vehicle_year': 2002, 'vehicle_make': 'DODG', 'license_state': 'NY', 'tow_location': 'VIRGINIA/W TUPPER', 'city': 'Buffalo', 'state': 'NY', 'zip': '14201', 'tow_reason': 'AI', 'tow_description': 'ACCIDENT', 'location_1': "{'latitude': '42.895771968431', 'longitude': '-78.880117965917'}", 'latitude': 42.89577196843054, 'longitude': -78.88011796591674, 'council_district': 'FILLMORE', 'police_district': 'District B', 'census_tract': '68', 'census_block_group': '3', 'census_block': '3012', 'neighborhood': 'UNKNOWN'},

{'unique_key': '2013092012SBA', 'tow_date': '2013-09-20T00:00:00.000', 'agency': 'SBA', 'vehicle_year': 2, 'vehicle_make': 'BUIC', 'license_state': 'NY', 'tow_location': '1414 ELMWOOD', 'city': 'Buffalo', 'state': 'NY', 'zip': '14207', 'tow_reason': 'IL', 'tow_description': 'ILLEGAL VEHICLE', 'location_1': "{'latitude': '42.936050942499', 'longitude': '-78.878311719861'}", 'latitude': 42.93605094249884, 'longitude': -78.87831171986092, 'council_district': 'NORTH', 'police_district': 'District D', 'census_tract': '55', 'census_block_group': '4', 'census_block': '4001', 'neighborhood': 'UNKNOWN'},

{'unique_key': '201402086SBA', 'tow_date': '2014-02-08T00:00:00.000', 'agency': 'SBA', 'vehicle_year': 1999, 'vehicle_make': 'HOND', 'license_state': 'NY', 'tow_location': 'RT 198/ELMWOOD', 'city': 'Buffalo', 'state': 'NY', 'zip': '14216', 'tow_reason': 'AI', 'tow_description': 'ACCIDENT', 'location_1': "{'latitude': '42.934279967964', 'longitude': '-78.877526952454'}", 'latitude': 42.934279967963626, 'longitude': -78.87752695245396, 'council_district': 'NORTH', 'police_district': 'District D', 'census_tract': '55', 'census_block_group': '4', 'census_block': '4007', 'neighborhood': 'UNKNOWN'},

{'unique_key': '200703032DPE', 'tow_date': '2007-03-03T00:00:00.000', 'agency': 'DPE', 'vehicle_year': 1998, 'vehicle_make': 'HOND', 'license_state': 'NY', 'tow_location': '154 ESSER', 'city': 'Buffalo', 'state': 'NY', 'zip': '14207', 'tow_reason': 'IL', 'tow_description': 'ILLEGAL VEHICLE', 'location_1': "{'latitude': '42.957094989887', 'longitude': '-78.90509151662'}", 'latitude': 42.95709498988724, 'longitude': -78.90509151661976, 'council_district': 'NORTH', 'police_district': 'District D', 'census_tract': '58.01', 'census_block_group': '3', 'census_block': '3005', 'neighborhood': 'UNKNOWN'},

{'unique_key': '200902182JMA', 'tow_date': '2009-02-18T00:00:00.000', 'agency': 'JMA', 'vehicle_year': 1998, 'vehicle_make': 'DODG', 'license_state': 'NY', 'tow_location': '693 EAST FERRY', 'city': 'Buffalo', 'state': 'NY', 'zip': '14211', 'tow_reason': 'IL', 'tow_description': 'ILLEGAL VEHICLE', 'location_1': "{'latitude': '42.914534429307', 'longitude': '-78.836284156378'}", 'latitude': 42.91453442930668, 'longitude': -78.83628415637776, 'council_district': 'MASTEN', 'police_district': 'District C', 'census_tract': '34', 'census_block_group': '4', 'census_block': '4001', 'neighborhood': 'UNKNOWN'},

{'unique_key': '200905176RIV', 'tow_date': '2009-05-17T00:00:00.000', 'agency': 'RIV', 'vehicle_year': 2008, 'vehicle_make': 'CHEV', 'license_state': 'NY', 'tow_location': '455 BERKSHIRE', 'city': 'Buffalo', 'state': 'NY', 'zip': '14215', 'tow_reason': 'IL', 'tow_description': 'ILLEGAL VEHICLE', 'location_1': "{'latitude': '42.941098974736', 'longitude': '-78.811347365474'}", 'latitude': 42.941098974736406, 'longitude': -78.81134736547351, 'council_district': 'UNIVERSITY', 'police_district': 'District E', 'census_tract': '43', 'census_block_group': '6', 'census_block': '6002', 'neighborhood': 'UNKNOWN'},

{'unique_key': '200805081GAR', 'tow_date': '2008-05-08T00:00:00.000', 'agency': 'GAR', 'vehicle_year': 7, 'vehicle_make': 'NISS', 'license_state': 'NY', 'tow_location': '568 BRECKENRIDGE', 'city': 'Buffalo', 'state': 'NY', 'zip': '14222', 'tow_reason': 'IP', 'tow_description': 'ILLEGALLY PARKED', 'location_1': "{'latitude': '42.916979379066', 'longitude': '-78.880114287074'}", 'latitude': 42.916979379065886, 'longitude': -78.8801142870745, 'council_district': 'DELAWARE', 'police_district': 'District D', 'census_tract': '65.01', 'census_block_group': '1', 'census_block': '1002', 'neighborhood': 'UNKNOWN'},

{'unique_key': '2011050413DPE', 'tow_date': '2011-05-04T00:00:00.000', 'agency': 'DPE', 'vehicle_year': 99, 'vehicle_make': 'FORD', 'license_state': 'NY', 'tow_location': '335 S. OGDEN', 'city': 'Buffalo', 'state': 'NY', 'zip': '14206', 'tow_reason': 'IL', 'tow_description': 'ILLEGAL VEHICLE', 'location_1': "{'latitude': '42.870147901777', 'longitude': '-78.802015400048'}", 'latitude': 42.87014790177672, 'longitude': -78.8020154000478, 'council_district': 'LOVEJOY', 'police_district': 'District A', 'census_tract': '19', 'census_block_group': '2', 'census_block': '2002', 'neighborhood': 'UNKNOWN'},

{'unique_key': '201201112DPE', 'tow_date': '2012-01-11T00:00:00.000', 'agency': 'DPE', 'vehicle_year': 2002, 'vehicle_make': 'CHEV', 'license_state': 'NY', 'tow_location': '1847 SOUTH PARK', 'city': 'Buffalo', 'state': 'NY', 'zip': '14220', 'tow_reason': 'IL', 'tow_description': 'ILLEGAL VEHICLE', 'location_1': "{'latitude': '42.848454363228', 'longitude': '-78.823758859745'}", 'latitude': 42.84845436322756, 'longitude': -78.82375885974496, 'council_district': 'SOUTH', 'police_district': 'District A', 'census_tract': '2', 'census_block_group': '3', 'census_block': '3000', 'neighborhood': 'UNKNOWN'},

{'unique_key': '20110609500RIV', 'tow_date': '2011-06-09T00:00:00.000', 'agency': 'RIV', 'vehicle_year': 0, 'vehicle_make': 'NISS', 'license_state': 'NY', 'tow_location': '279 SIUMMIT', 'city': 'Buffalo', 'state': 'NY', 'zip': '14214', 'tow_reason': 'GA', 'tow_description': 'GONE ON ARRIVAL', 'location_1': "{'latitude': '42.940601675459', 'longitude': '-78.847786815735'}", 'latitude': 42.940601675458645, 'longitude': -78.84778681573512, 'council_district': 'DELAWARE', 'police_district': 'District D', 'census_tract': '52.01', 'census_block_group': '1', 'census_block': '1003', 'neighborhood': 'UNKNOWN'},

{'unique_key': '200709127DPE', 'tow_date': '2007-09-12T00:00:00.000', 'agency': 'DPE', 'vehicle_make': 'MITT', 'tow_location': '208 SCHUELE', 'city': 'Buffalo', 'state': 'NY', 'zip': '14215', 'tow_reason': 'IL', 'tow_description': 'ILLEGAL VEHICLE', 'location_1': "{'latitude': '42.919588109317', 'longitude': '-78.826601647626'}", 'latitude': 42.91958810931662, 'longitude': -78.82660164762598, 'council_district': 'MASTEN', 'police_district': 'District E', 'census_tract': '34', 'census_block_group': '2', 'census_block': '2000', 'neighborhood': 'UNKNOWN'},

{'unique_key': '2013111212DPE', 'tow_date': '2013-11-12T00:00:00.000', 'agency': 'DPE', 'vehicle_year': 2000, 'vehicle_make': 'CHRY', 'license_state': 'NY', 'tow_location': 'AUBURN/PARKDALE', 'city': 'Buffalo', 'state': 'NY', 'zip': '14213', 'tow_reason': 'IL', 'tow_description': 'ILLEGAL VEHICLE', 'location_1': "{'latitude': '42.91850495521', 'longitude': '-78.888128989064'}", 'latitude': 42.91850495521016, 'longitude': -78.88812898906403, 'council_district': 'NIAGARA', 'police_district': 'District D', 'census_tract': '65.01', 'census_block_group': '4', 'census_block': '4002', 'neighborhood': 'UNKNOWN'},

{'unique_key': '2010102611RIV', 'tow_date': '2010-10-26T00:00:00.000', 'agency': 'RIV', 'vehicle_year': 2003, 'vehicle_make': 'MITS', 'license_state': 'NY', 'tow_location': '245 HUMBOLDT', 'city': 'Buffalo', 'state': 'NY', 'zip': '14208', 'tow_reason': 'IL', 'tow_description': 'ILLEGAL VEHICLE', 'location_1': "{'latitude': '42.926652428198', 'longitude': '-78.84935424949'}", 'latitude': 42.926652428197606, 'longitude': -78.84935424948956, 'council_district': 'MASTEN', 'police_district': 'District E', 'census_tract': '52.02', 'census_block_group': '1', 'census_block': '1002', 'neighborhood': 'UNKNOWN'},

{'unique_key': '2008051613DPE', 'tow_date': '2008-05-16T00:00:00.000', 'agency': 'DPE', 'vehicle_year': 1998, 'vehicle_make': 'NISS', 'license_state': 'NY', 'tow_location': '1016 EAST FERRY', 'city': 'Buffalo', 'state': 'NY', 'zip': '14215', 'tow_reason': 'IL', 'tow_description': 'ILLEGAL VEHICLE', 'location_1': "{'latitude': '42.914523911243', 'longitude': '-78.82628826168'}", 'latitude': 42.91452391124338, 'longitude': -78.82628826168033, 'council_district': 'MASTEN', 'police_district': 'District E', 'census_tract': '34', 'census_block_group': '1', 'census_block': '1005', 'neighborhood': 'UNKNOWN'},

{'unique_key': '200709074GAR', 'tow_date': '2007-09-07T00:00:00.000', 'agency': 'GAR', 'vehicle_year': 1998, 'vehicle_make': 'HOND', 'license_state': 'NY', 'tow_location': '370 LAFAYETTE', 'city': 'Buffalo', 'state': 'NY', 'zip': '14213', 'tow_reason': 'ST', 'tow_description': 'STOLEN VEHICLE', 'location_1': "{'latitude': '42.92027445075', 'longitude': '-78.8846538068'}", 'latitude': 42.92027445075032, 'longitude': -78.88465380680023, 'council_district': 'NIAGARA', 'police_district': 'District D', 'census_tract': '63.01', 'census_block_group': '3', 'census_block': '3003', 'neighborhood': 'UNKNOWN'},

{'unique_key': '200808076DPE', 'tow_date': '2008-08-07T00:00:00.000', 'agency': 'DPE', 'vehicle_year': 0, 'vehicle_make': 'HOND', 'license_state': 'NY', 'tow_location': '208 ONTARIO', 'city': 'Buffalo', 'state': 'NY', 'zip': '14207', 'tow_reason': 'ST', 'tow_description': 'STOLEN VEHICLE', 'location_1': "{'latitude': '42.950494878825', 'longitude': '-78.903134445873'}", 'latitude': 42.9504948788245, 'longitude': -78.90313444587314, 'council_district': 'NORTH', 'police_district': 'District D', 'census_tract': '58.02', 'census_block_group': '1', 'census_block': '1006', 'neighborhood': 'UNKNOWN'}]

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

Here is the completed code for this problem. Comments are included, go through it, learn how things work and let me know if you have any doubts or if you need anything to change. If you are satisfied with the solution, please rate the answer. If not, PLEASE let me know before you rate, I’ll help you fix whatever issues. Thanks

Note: Please maintain proper code spacing (indentation), just copy the code part and paste it in your compiler/IDE directly, no modifications required.

If you pasted this code correctly, and called print(list_descriptions(data)), then the output will be ['ACCIDENT', 'ILLEGALLY PARKED', 'ILLEGAL VEHICLE', 'GONE ON ARRIVAL', 'STOLEN VEHICLE']

#code

'''
method return a list of strings which are the values associated with key='tow_description'
in the given list of dictionaries. the returned list will not contain duplicates
'''
def list_descriptions(data):
    #creating an empty list
    accumulator = []
    #looping through each dict in data list
    for d in data:
        #fetching value associated with key='tow_description', assuming key exist
        value = d['tow_description']
        #if value is not already there in accumulator, appending to it
        if value not in accumulator:
            accumulator.append(value)
    #returning the list
    return accumulator
Add a comment
Know the answer?
Add Answer to:
list_descriptions Define a function named list_descriptions with one parameter. This parameter will be a list of...
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
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