runtime
167 / 500
question 167 Nested Data Structures · medium

Earthquakes per region

A seismology dashboard groups a page of USGS events by region and shows how many there were and the largest magnitude. The region is the part of place after its last ", " ("79 km S of Champerico, Guatemala" → "Guatemala"); a place with no comma is its own region ("Southern Alaska").

Functionregion_stats(features)
featuresGeoJSON features with properties → place and properties → mag
Returns{region: {"count": n, "max_mag": m}}, regions in the order first seen
Rulesevents whose mag is None are left out entirely
Examples
callregion_stats([{'type': 'Feature', 'id': 'us6000pw7c', 'properties': {'mag': 4.3, 'place': '79 km S of Champerico, Guatemala'}, 'geometry': {'type': 'Point', 'coordinates': [-91.9089, 13.5727, 10]}}, {'type': 'Feature', 'id': 'ak0252r9gt13', 'properties': {'mag': 2.7, 'place': 'Southern Alaska'}, 'geometry': {'type': 'Point', 'coordinates': [-147.2371, 61.4029, 9.6]}}, {'type': 'Feature', 'id': 'us6000pw7t', 'properties': {'mag': 4.4, 'place': '69 km S of Champerico, Guatemala'}, 'geometry': {'type': 'Point', 'coordinates': [-91.867, 13.6626, 37.388]}}, {'type': 'Feature', 'id': 'us7000pp3c', 'properties': {'mag': 3.6, 'place': '48 km SSE of Adak, Alaska'}, 'geometry': {'type': 'Point', 'coordinates': [-176.3629, 51.4765, 33.783]}}])returns{'Guatemala': {'count': 2, 'max_mag': 4.4}, 'Southern Alaska': {'count': 1, 'max_mag': 2.7}, 'Alaska': {'count': 1, 'max_mag': 3.6}}
callregion_stats([{'type': 'Feature', 'id': 'ak0252r9gt13', 'properties': {'mag': 2.7, 'place': 'Southern Alaska'}, 'geometry': {'type': 'Point', 'coordinates': [-147.2371, 61.4029, 9.6]}}])returns{'Southern Alaska': {'count': 1, 'max_mag': 2.7}}
callregion_stats([])returns{}

Loading your progress…

Earthquakes per region — Python practice · Runtime