I'm new to python
I'm attempting to use the Hans volcano api to produce a map (https://volcanoes.usgs.gov/hans2/apiv2/volcanoApi/allWithNotice)
When printing my URL as json I am presented with many volcanoes in this format
[{'obsAbbr': 'avo', 'volcCd': 'ak6', 'volcName': 'Akutan', 'volcUrl': 'https://avo.alaska.edu/volcanoes/volcinfo.php?volcname=Akutan', 'vnum': '311320', 'imgUrl': 'https://avo.alaska.edu/images/dbimages/display/1108076476_60_3.jpg', 'threat': 'Very High Threat'},
From this I'm looking to extract volcano names. When making my dictionary I'm given one volcano only. I'm looking to obtain all the volcano names from this json file.
v = requests.get(url2.format()).json()
volcano = {
'name' : v[0]['volcName'],
}
Any help would be appreciated, cheers
volcano = { 'name' : [d['volcName'] for d in v]}? You'll have to loop throughv. Where you assign it depends on what format you want it in.[{'name':'Akutan'},{'name':'Aniakchak'},...]); or only 1 dict where the value for name is a list of names? (like this{'name':['Akutan','Aniakchak',...]})