title: Difference between two values in a list of tuples
body: <p>I have a list of tuples, each representing a date and an an associated value for that day. For example</p>
  
  <pre><code>team_effort = [('2012-09-10', 27), ('2012-09-11', 28), 
                 ('2012-09-12', 28), ('2012-09-13', 31), ('2012-09-14', 31)]
  </code></pre>
  
  <p>I need to calculate the difference in value between each day, and return a similar list of tuples each with a date and value (0 if the value is the same or has decreased, or the difference if it has increased)</p>
  
  <p>So in this example I want to return </p>
  
  <pre><code>[('2012-09-10', 0), ('2012-09-11', 1), 
   ('2012-09-12', 0), ('2012-09-13', 3), ('2012-09-14', 0)]
  </code></pre>
  
  <p>The following list comprehension works (in 2.4+)</p>
  
  <pre><code>[(data[0], 0) if i == 0
      else (data[0], data[1] - team_effort[i-1][1]) if data[1] &gt; team_effort[i-1][1]
      else (data[0], 0)
      for i, data in enumerate(team_effort)]
  </code></pre>
  
  <p>But I think there could be a more elegant solution? Any suggestions?</p>
  
  <p>Note I have to treat effort_data[0] differently, as it will always be zero and if it got to the effort_data[i-1][1] line, it would look at the last item in the list (aka effort_data[-1][1].</p>