-1

I'm doing some reverse Geo coding to convert latitude and longitude to a location name:

def reverseGeocode(coordinates): result = rg.search(coordinates) print(result) if __name__ == "__main__": coord = (-33.936952777777776, 18.39005) reverseGeocode(coord) 

Result has following format:

[OrderedDict([('lat', '-33.92584'), ('lon', '18.42322'), ('name', 'Cape Town'), ('admin1', 'Western Cape'), ('admin2', 'City of Cape Town'), ('cc', 'ZA')])] 

How can i get to certain element of this OrderedDict to have just a location 'name'? That would be 'Cape Town' in this example.

4
  • 2
    In the same way you retrieve the "name" key from an ordinary dict. An OrderedDict has only a special string representation. Commented Jan 4, 2020 at 17:59
  • 1
    Or if you want by index: stackoverflow.com/questions/10058140/… Commented Jan 4, 2020 at 18:00
  • 3
    Note that result is actually a list of OrderedDict Commented Jan 4, 2020 at 18:00
  • What is your question, exactly? If you want to know how to use a dictionary, then that's been asked before. As @MichaelButscher pointed out, you have a list of OrderedDicts, it isn't clear if you understand that. Commented Jan 4, 2020 at 18:25

1 Answer 1

0

result[0]['name'] # == 'Cape Town'

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.