Lingjie's Web Dict Exercise

by Lingjie Wang

10 Apr 2016

Exercise:

Reflection: I’ve spent some time thinking about why the data extracted is in those types: js is a dictionary, js[‘results’] is a list, and js[‘results][0] is a dictionary. I was confused that, now that the list js[‘result’] only had one element, why not just making it a dictionary? Then I saw the list of js[‘results’][0][‘address_components’], where three keys with the same name “short_name” might exist. As a key in a dictionary should be distinct, we need to put those keys in different dictionaries, and put these dictionaries in a list to extract data we need precisely. That’s what I think about most during this exercise.

For the output, I choose to print out latitude, longitude, address, addministrative area and country, if the address entered is on the city-level. I use try and except to handle the situation that the user directly enters name of a province/state or a country, and I use pass for the except part.

Lingjie Wang is a first year master student studying Statistics and Operations Research Find Lingjie Wang on Twitter, Github, and on the web.