title: How to match a list of dates to a pattern?
body: <p>I have a Python <code>list</code> of <code>tuples</code> with three objects: a <code>string</code> (ex: title), <code>date</code> and another <code>string</code> (ex: a name).</p>
  
  <p><strong>Example:</strong></p>
  
  <pre><code>scientific_works = [
      ('SW 1', datetime.date(2000, 10, 15), 'auth 1'),
      ('SW 2', datetime.date(2000, 11, 3), 'auth 1'),
      ('SW 3', datetime.date(2000, 11, 4), 'auth 1'),
      ('SW 4', datetime.date(2000, 12, 1), 'auth 1'),
  ]
  </code></pre>
  
  <p><strong>Then I have a pattern:</strong></p>
  
  <p>from <code>date</code> until <code>date</code>, (at least) <code>int</code> items from <code>list</code> per <code>int</code> days/weeks/months/years </p>
  
  <p>Example:</p>
  
  <pre><code>from  datetime.date(2000, 11, 1)
  until datetime.date(2000, 11, 30)
  1 item per day
  </code></pre>
  
  <p>What I would like the algorithm to do:</p>
  
  <ul>
  <li>Given that list and that pattern, do the filtered items match the rules?</li>
  </ul>
  
  <p>In the case of examples, this pattern would match 2 items, all of them matching the rule here: <code>1 item complete per day</code>, however, since there aren't <code>an item</code> for each day block, the algorithm would return <code>false</code>.</p>
  
  <p>Another example:</p>
  
  <ul>
  <li>Is there (at least) Int_1 amount of items (works) per Int_2 (day/week/month)?
  <ul>
  <li>1 work per day would mean at least 1 item per 1 day block of given the date range. 2 works per week would mean, at least 2 works each week (or 7 day block) of date range. </li>
  </ul></li>
  </ul>
  
  <p>I can iterate over the list and find out which items match <code>from</code> and <code>until</code> pattern, of course. </p>
  
  <p>However, I am really confused over matching them with the rest of the rules to see if its a positive or a negative match.</p>
  
  <p>My question:</p>
  
  <ul>
  <li>How can I construct an algorithm, provide it with a list and a pattern of rules (x items per y day OR week OR month OR year), and see if it matches or not?</li>
  </ul>
  
  <p>I am working on a little component for an application where given a certain data (list) and rules (pattern), if an author unlocks a reward or not.</p>
  
  <p>I have completed udacity's several Python classes, including most of algorithms but really can not find my way around this.</p>
  
  <p>So far I thought of this:</p>
  
  <ol>
  <li>Filter list items with the given date range.</li>
  <li>Calculate the range blocks within the range: 1 day from d1 until d2 = 5 days - 1 week from d1 until d2 = 3 weeks</li>
  <li>Create a loop in range of <code>int</code> calculated above.</li>
  <li>Convert weeks, months, years to days in each step of the loop.</li>
  <li>Add the amount to the start date and see if items match the date range.</li>
  <li>Add the amount to next start of date range and repeat.</li>
  </ol>
  
  <p>However, this doesn't work and I don't think converting blocks to days is efficient at all.</p>
  
  <p>Thank you.</p>