title: Python 3 - Search List or Dictionary
body: <p>I am writing a program to retrieve json data, in which the data values are fixed.</p>
  
  <p>The values returned will be either </p>
  
  <pre><code>'UN','VP','PO','MO','GO','VG','EX'
  </code></pre>
  
  <p>When the program runs, the expected return will be something like the following:</p>
  
  <pre><code>outlook1 = 'UN'
  outlook2 = 'VP'
  outlook3 = 'PO'
  outlook4 = 'MO'
  outlook5 = 'GO'
  outlook6 = 'VG'
  outlook7 = 'EX'
  </code></pre>
  
  <p>I want the program to read the two letter value assigned and change it to a more descriptive output.</p>
  
  <pre><code>a = ['UN','VP','PO','MO','GO','VG','EX']
  b = ['Unknown', 'Very Poor', 'Poor', 'Moderate', 'Good', 'Very Good', 
  'Excellent']
  </code></pre>
  
  <p>so 'VP' will become 'Very Poor'</p>
  
  <p>I thought of using a dictionary also but cannot think of how to match keys and values to data that has been set.</p>
  
  <pre><code>dict1 = {'UN':'Unknown','VP':'Very Poor','PO':'Poor','MO':'Moderate',
          'GO':'Good','VG':'Very Good','EX':'Excellent'}
  </code></pre>
  
  <p>the only way I have been able to solve this so far is with a very long if-elif statement</p>
  
  <pre><code>x = []
  
  if outlook1 == 'UN':
      x.append(b[0])
  elif outlook1 == 'VP':
      x.append(b[1])
  elif outlook1 == 'PO':
      x.append(b[2])
  elif outlook1 == 'MO':
      x.append(b[3])
  elif outlook1 == 'GO':
      x.append(b[4])
  elif outlook1 == 'VG':
      x.append(b[5])
  elif outlook1 == 'EX':
      x.append(b[6])
  </code></pre>
  
  <p>Here is my code: </p>
  
  <pre><code>import requests
  import urllib.parse
  import texttable as tt
  
  main_api = 'example.org'
  key='123456789'
  
  url = main_api + urllib.parse.urlencode({'key':key})
  
  json_data = requests.get(url).json()
  
  block1_time = json_data["SiteRep"]["DV"]["Location"]["Period"][1]["Rep"][0]["$"]
  block1_f = json_data["SiteRep"]["DV"]["Location"]["Period"][1]["Rep"][0]["F"]
  block1_s = json_data["SiteRep"]["DV"]["Location"]["Period"][1]["Rep"][0]["S"]
  block1_h = json_data["SiteRep"]["DV"]["Location"]["Period"][1]["Rep"][0]["H"]
  block1_t = json_data["SiteRep"]["DV"]["Location"]["Period"][1]["Rep"][0]["T"]
  block1_v = json_data["SiteRep"]["DV"]["Location"]["Period"][1]["Rep"][0]["V"]
  block1_d = json_data["SiteRep"]["DV"]["Location"]["Period"][1]["Rep"][0]["D"]
  block1_u = json_data["SiteRep"]["DV"]["Location"]["Period"][1]["Rep"][0]["U"]
  block1_w = json_data["SiteRep"]["DV"]["Location"]["Period"][1]["Rep"][0]["W"]
  block1_p = json_data["SiteRep"]["DV"]["Location"]["Period"][1]["Rep"][0]["Pp"]
  
  dates = ['00:00','03:00','06:00','09:00','12:00','15:00','18:00','21:00']
  temp = []
  feels = []
  speed = []
  direc = []
  humid = []
  visib = []
  wtype = []
  prob = []
  uvind = []
  
  descr = ['Unknown', 'Very Poor', 'Poor', 'Moderate', 'Good', 'Very Good', 
      'Excellent'] #[0-6]
  if block1_v == 'UN':
      visib.append(descr[0])
  elif block1_v == 'VP':
      visib.append(descr[1])
  elif block1_v == 'PO':
      visib.append(descr[2])
  elif block1_v == 'MO':
      visib.append(descr[3])
  elif block1_v == 'GO':
      visib.append(descr[4])
  elif block1_v == 'VG':
      visib.append(descr[5])
  elif block1_v == 'EX':
      visib.append(descr[6])
  </code></pre>
  
  <p>The empty lists are appended and used to populate a TextTable.</p>
  
  <p>There must be an easier way in python. Hope this makes things clearer and any Help Much Appreciated.</p>
  
  <p>****UPDATE****json data****</p>
  
  <p>{"SiteRep":{"Wx":{"Param":[{"name":"F","units":"C","$":"Feels Like Temperature"},{"name":"G","units":"mph","$":"Wind Gust"},{"name":"H","units":"%","$":"Screen Relative Humidity"},{"name":"T","units":"C","$":"Temperature"},{"name":"V","units":"","$":"Visibility"},{"name":"D","units":"compass","$":"Wind Direction"},{"name":"S","units":"mph","$":"Wind Speed"},{"name":"U","units":"","$":"Max UV Index"},{"name":"W","units":"","$":"Weather Type"},{"name":"Pp","units":"%","$":"Precipitation Probability"}]},"DV":{"dataDate":"2017-11-12T18:00:00Z","type":"Forecast","Location":{"i":"26","lat":"53.3336","lon":"-2.85","name":"LIVERPOOL JOHN LENNON AIRPORT","country":"ENGLAND","continent":"EUROPE","elevation":"22.0","Period":[{"type":"Day","value":"2017-11-12Z","Rep":[{"D":"NNW","F":"4","G":"22","H":"57","Pp":"0","S":"18","T":"8","V":"VG","W":"1","U":"1","$":"900"},{"D":"NNW","F":"2","G":"29","H":"65","Pp":"0","S":"11","T":"6","V":"VG","W":"0","U":"0","$":"1080"},{"D":"NNW","F":"2","G":"27","H":"67","Pp":"0","S":"11","T":"5","V":"VG","W":"0","U":"0","$":"1260"}]},{"type":"Day","value":"2017-11-13Z","Rep":[{"D":"NNW","F":"1","G":"25","H":"71","Pp":"0","S":"11","T":"5","V":"VG","W":"0","U":"0","$":"0"},{"D":"NNW","F":"0","G":"22","H":"74","Pp":"0","S":"11","T":"4","V":"VG","W":"0","U":"0","$":"180"},{"D":"NNW","F":"0","G":"18","H":"77","Pp":"0","S":"9","T":"3","V":"VG","W":"0","U":"0","$":"360"},{"D":"W","F":"2","G":"9","H":"82","Pp":"1","S":"2","T":"4","V":"GO","W":"3","U":"1","$":"540"},{"D":"S","F":"5","G":"7","H":"74","Pp":"5","S":"4","T":"6","V":"GO","W":"7","U":"1","$":"720"},{"D":"SSW","F":"6","G":"11","H":"80","Pp":"5","S":"7","T":"7","V":"GO","W":"7","U":"1","$":"900"},{"D":"SSW","F":"5","G":"16","H":"79","Pp":"6","S":"7","T":"7","V":"GO","W":"7","U":"0","$":"1080"},{"D":"SSW","F":"5","G":"18","H":"79","Pp":"6","S":"9","T":"7","V":"VG","W":"7","U":"0","$":"1260"}]},{"type":"Day","value":"2017-11-14Z","Rep":[{"D":"SSW","F":"5","G":"18","H":"87","Pp":"50","S":"9","T":"8","V":"VG","W":"12","U":"0","$":"0"},{"D":"SW","F":"7","G":"20","H":"92","Pp":"52","S":"9","T":"9","V":"GO","W":"12","U":"0","$":"180"},{"D":"WSW","F":"8","G":"20","H":"91","Pp":"14","S":"11","T":"10","V":"VG","W":"7","U":"0","$":"360"},{"D":"WSW","F":"8","G":"20","H":"91","Pp":"17","S":"11","T":"10","V":"GO","W":"8","U":"1","$":"540"},{"D":"W","F":"10","G":"16","H":"92","Pp":"61","S":"9","T":"12","V":"MO","W":"12","U":"1","$":"720"},{"D":"SW","F":"11","G":"11","H":"92","Pp":"53","S":"7","T":"11","V":"GO","W":"12","U":"1","$":"900"},{"D":"S","F":"10","G":"9","H":"94","Pp":"15","S":"4","T":"10","V":"MO","W":"7","U":"0","$":"1080"},{"D":"WSW","F":"9","G":"13","H":"92","Pp":"15","S":"9","T":"10","V":"GO","W":"8","U":"0","$":"1260"}]},{"type":"Day","value":"2017-11-15Z","Rep":[{"D":"WSW","F":"9","G":"13","H":"93","Pp":"54","S":"7","T":"10","V":"GO","W":"12","U":"0","$":"0"},{"D":"WSW","F":"9","G":"11","H":"93","Pp":"14","S":"7","T":"10","V":"GO","W":"7","U":"0","$":"180"},{"D":"NW","F":"8","G":"11","H":"91","Pp":"11","S":"7","T":"9","V":"GO","W":"7","U":"0","$":"360"},{"D":"SE","F":"8","G":"11","H":"91","Pp":"7","S":"7","T":"10","V":"GO","W":"7","U":"1","$":"540"},{"D":"S","F":"10","G":"11","H":"87","Pp":"8","S":"7","T":"11","V":"GO","W":"7","U":"1","$":"720"},{"D":"SSE","F":"10","G":"13","H":"87","Pp":"15","S":"7","T":"11","V":"GO","W":"8","U":"1","$":"900"},{"D":"SSE","F":"8","G":"13","H":"92","Pp":"11","S":"7","T":"10","V":"GO","W":"7","U":"0","$":"1080"},{"D":"S","F":"8","G":"16","H":"92","Pp":"8","S":"9","T":"10","V":"GO","W":"7","U":"0","$":"1260"}]},{"type":"Day","value":"2017-11-16Z","Rep":[{"D":"S","F":"7","G":"16","H":"93","Pp":"7","S":"9","T":"9","V":"GO","W":"7","U":"0","$":"0"},{"D":"S","F":"7","G":"16","H":"93","Pp":"7","S":"9","T":"9","V":"GO","W":"7","U":"0","$":"180"},{"D":"S","F":"7","G":"18","H":"92","Pp":"7","S":"9","T":"9","V":"GO","W":"7","U":"0","$":"360"},{"D":"S","F":"7","G":"20","H":"90","Pp":"14","S":"11","T":"10","V":"GO","W":"7","U":"1","$":"540"},{"D":"SSW","F":"9","G":"25","H":"84","Pp":"9","S":"13","T":"11","V":"GO","W":"7","U":"1","$":"720"},{"D":"SW","F":"8","G":"27","H":"84","Pp":"55","S":"16","T":"11","V":"GO","W":"12","U":"1","$":"900"},{"D":"SW","F":"7","G":"25","H":"79","Pp":"14","S":"11","T":"10","V":"VG","W":"7","U":"0","$":"1080"},{"D":"W","F":"6","G":"25","H":"78","Pp":"14","S":"13","T":"9","V":"GO","W":"7","U":"0","$":"1260"}]}]}}}}</p>