'Either for loop isn't looping or dictionary isn't saving

Essentially I am pulling data from an API about earthquake data. I'm trying to set up a function that allows me to put in lon/lat coordinates and then get a dictionary with number of years quakes given a certain number of years back. I can't tell which but either my for loop isn't looping properly or the dictionaries are just overwriting and giving my the last data points. My goal is to create two dictionaries, each with the number of earthquakes in an area over the past 1, 5, and 10 years. Keep in mind this is an assignment for a very basic/intro python class so I'm not concerned about an optimized code, I just need to know whats going wrong.

Berlin_data = {}
SanF_data = {}
def earthquakes(town, lat, lon):
    year_list = ["2021-04-20", "2017-04-20", "2012-04-20"]
    for year in year_list:
        parameters = {
                "format" : "geojson",
                "starttime" : year,
                "latitude" : lat,
                "longitude" : lon,
                "maxradiuskm": 300,
                "minmagnitude" : 4.0
            }
        result = requests.get(url, params=parameters)
        if result.status_code == 200:
            data = result.json()
            if town == "SanF":
                SanF_data[year] = data
                return data
            if town == "Berlin":
                Berlin_data[year] = data
                return data
        else:
            print(result.status_code)

earthquakes("SanF",37.7739,-122.4312)
earthquakes("Berlin",52.520008,13.404954)

for year in SanF_data:
    print(f"Berlin :{Berlin_data[year]['count']}     &      San Fransisco:{SanF_data[year]['count']}")

My hope was that this would give me 3 lines but instead I just get

Berlin :7 & San Fransisco:17



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source