title: Working with lists of tuples python
body: <p>I am working with a dictionary where each key contain a list of tuples. It looks like this:</p>
  
  <pre><code>dict1 = {'key1': [(time1, value1), (time2, value2), (time3, value3)],
           'key2': [(time4, value4), (time5, value5), (time6, value6)],
           'key3': [(time7, value7), (time8, value8), (time9, value9)], ...}
  </code></pre>
  
  <p>What is wish to do for each key is to find the largest drop in 'valueX' from 'timeX' to 'timeY'.</p>
  
  <p>The tuples are orderes so that </p>
  
  <pre><code>time1 &lt; time2 &lt; time3 
  </code></pre>
  
  <p>And it is (typically) true that</p>
  
  <pre><code>value1 &gt; value2 &gt; value3
  </code></pre>
  
  <p>Both things are true for all keys. </p>
  
  <p>So looking at the first key, what I wish to do is to calculate </p>
  
  <pre><code>value2 - value1 and value3 - value2
  </code></pre>
  
  <p>And save the times that the biggest drop occurs. Let's say that</p>
  
  <pre><code>value2 - value1 &gt; value3 - value2
  </code></pre>
  
  <p>Then I wish to save time1 and time2, since it was between those two time values that the largest drop occured.</p>
  
  <p>I am thinking to use a for-loop like the following:</p>
  
  <pre><code>for key in dict1:
      for i in dict1[key]:
  </code></pre>
  
  <p>But I cannot figure out how to </p>
  
  <p>1) loop through the values, calculate the difference between the present value and the past value, save this and compare it the the largest drop that has been observed </p>
  
  <p>2) to save the times that correspond to the largest drop in 'value'.</p>
  
  <p>I hope you can help me out here. Thanks a lot.</p>