title: Find dictionary with greatest date less than or equal to variable, return value
body: <p>I installed the python <a href="https://github.com/zachwill/fred/blob/master/fred/core.py" rel="nofollow">package</a>  <code>fred</code>, using <code>pip install fred</code>, to obtain real time data from the FRED / ALFRED API.  </p>
  
  <p>My task now is to match an <em>assessment</em> date to the data -- so to extract values associated with the greatest <code>realtime_date</code> that's less than or equal to what i'm calling the assessment date (<code>aDate</code>).  </p>
  
  <p>The data itself is returned in a python dictionary, which contains lists, with each observation stored in a dictionary along with some meta-data -- each observation dict contains: a reference date (<code>date</code>), the realtime period that the request covered (<code>realtime_end</code>, <code>realtime_start</code>) and the value (<code>value</code>). </p>
  
  <p>I can see how to match the data to an assessment date when there is an exact match, but in the real world these are the exception.  I am looking for help to generalise this to an inequality. </p>
  
  <p>(note below i am using a variable <code>fredKey</code> -- whereas you must supply your own FRED API key to access FRED). </p>
  
  <pre><code>import fred
  fred.key(fredKey)
  CPIobvs = fred.observations('CPIAUCSL', realtime_start = "1990-01-01")
  aDate == "2008-02-15"
  
  for i in range(1, len(CPIobvs['observations']['observation'])):
      if CPIobvs['observations']['observation'][i]['realtime_start'] == aDate:
          print (CPIobvs['observations']['observation'][i]['date'], 
                  CPIobvs['observations']['observation'][i]['value']
                 )
  </code></pre>
  
  <p>For this example, I chose an annual benchmark revision date, to be sure to get something back.  In practice, I am usually going to be updating the simulation on dates where noting happened -- in which case my method returns nothing.  </p>
  
  <p>The solution seems to be to match to the greatest date (a <code>realtime_start</code> value) that's less than or equal to the assessment date (say <code>aDate == "2008-02-14"</code>).  How might i match to the greatest <code>realtime_date</code> that's less than or equal to <code>aDate</code>? </p>
  
  <p>thanks</p>