title: How to search through a JSON feed
body: <p>I'm using the code below and make a call to the Google Maps API and parse some JSON data.</p>
  
  <pre><code>def getLocalityFromPostCode(postcode):
      import urllib, json
      import pprint
      url = "http://maps.googleapis.com/maps/api/geocode/json?address=%s&amp;sensor=false" % postcode
      googleResponse = urllib.urlopen(url)
      jsonResponse = json.loads(googleResponse.read())
      return jsonResponse
  </code></pre>
  
  <p>This works fine. However, i only need the value from<code>['results']['address_components']</code> where the <code>'type'</code> is  <code>[ "locality", "political" ]</code> however, the index of this value differs depending on how precise the given postcode string is.</p>
  
  <p>If i give a straight poscode (like XX10) the value appears in the 0th item in the <code>address_components</code> list. However, if i give a city and postcode it appears in the 1st item.</p>
  
  <p>Can someone help me please. I need to search through address_components for the <code>[ "locality", "political" ]</code> value.</p>
  
  <p>EDIT</p>
  
  <p>You can view te feeds at <code>http://maps.googleapis.com/maps/api/geocode/json?address=sy4&amp;sensor=false</code> (just postcode) and <code>http://maps.googleapis.com/maps/api/geocode/json?address=47%20High%20Street%20Shrewsbury,%20SY4&amp;sensor=false</code> (full address).</p>
  
  <p>As you can see in example 1 the data I'm looking for is in index 1, whereas in the second example the data I'm looking for is in index 2.</p>