So I was trying to grab information about the distance between two cities and save the results in a variable
distance_result_dic = gmaps.distance_matrix("Sydney Town Hall",
"Parramatta, NSW",
mode="transit",
departure_time=now)
The result of print(distance_result_dic) is:
{
'destination_addresses': ['Parramatta NSW 2150, Australia'],
'origin_addresses': ['483 George St, Sydney NSW 2000, Australia'],
'rows': [{
'elements': [{
'distance': {'text': '24.4 km', 'value': 24414},
'duration': {'text': '44 mins', 'value': 2665},
'status': 'OK'
}]
}],
'status': 'OK'
}
Then I would like to access a certain value like 'value' so that i can save the 24414 in another Variable. I tried this:
distance_value = distance_result_dic['rows']['elements']['distance']['value']
But I get the following error message:
list indices must be integers or slices, not str
which indicates that the dictionary-element 'rows' contains a list. Yet I don't know how to access that list and its elements from the dictionary distance_result_dic directly