title: How to compare datetime object effectively
body: <p>I have a dictionary with around 15k records which is formatted like this:</p>
  
  <pre><code>sample = {0: {'Schedule': ['2017-05-11', '2019-04-30', '2018-10-13', '2019-05-31', '', '']},
        1: {'Schedule': ['2017-05-09', '2019-05-31', '', '', '2018-10-13', '2019-05-31']},
        2: {'Schedule': ['2017-05-02', '2020-02-29', '', '', '2018-10-12', '2020-02-29']}}
  </code></pre>
  
  <p>Now i have to compare the 1st, 3rd and 5th dates in <code>'Schedule'</code> with two datetime objects and see if falls within the range. I am doing the below, but the result is quite slow and takes like 20 seconds. Can anyone suggest a more efficient way of searching?</p>
  
  <p>Full sample code:</p>
  
  <pre><code>from datetime import datetime
  
  sample = {0: {'Schedule': ['2017-05-11', '2019-04-30', '2018-10-13', '2019-05-31', '', '']},
            1: {'Schedule': ['2017-05-09', '2019-05-31', '', '', '2018-10-13', '2019-05-31']},
            2: {'Schedule': ['2017-05-02', '2020-02-29', '', '', '2018-10-12', '2020-02-29']}}
  
  start_date = datetime.date(datetime.strptime("2018-10-12","%Y-%m-%d"))
  end_date = datetime.date(datetime.strptime("2018-10-16","%Y-%m-%d"))
  
  for k,v in sample.items():
      earliest = [dt for dt in [v["Schedule"][0],v["Schedule"][2],v["Schedule"][4]] if dt] #only need to check these 3 starting dates
      def check_earliest(_list):  #check if any date meets search criteria
          for i in _list:
              if start_date &lt;= datetime.date(datetime.strptime(i, "%Y-%m-%d")) &lt;= end_date:
                  return True
      if check_earliest(earliest):
          print ("Do something here...")
  </code></pre>