title: get min max values of items with same id if difference exists?
body: <p>I have two files that look like this with some differences between them:</p>
  
  <p>First file:</p>
  
  <pre><code> {16:[3, [-7, 87, 20, 32]]}
  {17:[2, [-3, 88, 16, 28], 3, [-6, 84, 20, 32]]}
  {18:[2, [-1, 88, 16, 28], 3, [-3, 84, 20, 32]]}
  {19:[2, [1, 89, 16, 28], 3, [-2, 85, 20, 32]]}
  {20:[2, [9, 94, 16, 28], 3, [1, 85, 20, 32]]}
  {21:[2, [12, 96, 16, 28], 3, [2, 76, 19, 31]]}
  {22:[2, [15, 97, 16, 28], 3, [4, 73, 19, 29]]}
  {23:[2, [18, 96, 16, 28], 3, [6, 71, 19, 29], 10, [-10, 60, 51, 82]]}
  {24:[2, [22, 97, 16, 28], 3, [9, 71, 19, 27], 10, [-5, 63, 49, 78]]}
  {25:[2, [25, 99, 16, 28], 3, [13, 71, 17, 26], 10, [-1, 64, 46, 77]]}
  {26:[2, [29, 101, 16, 28], 3, [17, 70, 16, 25], 10, [-1, 65, 45, 77]]}
  </code></pre>
  
  <p>Second file:</p>
  
  <pre><code>{16:[3, [-7, 86, 20, 32]]}
  {17:[2, [-3, 82, 16, 28], 3, [-6, 84, 20, 32]]}
  {18:[2, [-1, 88, 16, 27], 3, [-3, 84, 20, 32]]}
  {19:[2, [1, 89, 16, 28], 3, [-2, 84, 20, 32]]}
  {20:[2, [9, 94, 15, 28], 3, [1, 85, 20, 32]]}
  {21:[2, [12, 96, 16, 28], 3, [1, 76, 19, 31]]}
  {22:[2, [15, 97, 17, 28], 3, [4, 73, 19, 29]]}
  {23:[2, [18, 96, 18, 28], 3, [6, 71, 19, 29], 10, [-10, 60, 51, 82]]}
  {24:[2, [22, 97, 16, 28], 3, [9, 71, 20, 27], 10, [-5, 63, 49, 78]]}
  {25:[2, [25, 99, 16, 28], 3, [13, 71, 17, 26], 10, [-1, 64, 46, 77]]}
  {26:[2, [29, 101, 17, 28], 3, [17, 70, 16, 25], 10, [-1, 65, 45, 77]]}
  </code></pre>
  
  <p>I compare them both using difflib and print out the lines that have a difference in them.
  What i am trying to do is print out the minimum and maximum <code>frame</code> values that share the same <code>id</code>.</p>
  
  <p>The frame is the key in every line so the frames in this case range from <code>16</code> to <code>26</code>. The id is the value that preceeds every list of 4 values. So the id on the first line is <code>3</code>. The second line has two id's which are <code>2</code> and then <code>3</code>.</p>
  
  <p>So an example of what i'd like to write out is:</p>
  
  <pre><code>17 - 36
  </code></pre>
  
  <p>given that one of the <code>frames</code> that share the id <code>3</code> is different than the file that i am comparing with.</p>
  
  <p>For every difference like that, i need to write out a new file that only contains the start frame and the end frame, then i'll work on concatenating additional strings to each file.</p>
  
  <p>this is the current difflib usage that prints out each line that has a different:</p>
  
  <pre><code>def compare(f1, f2):
      with open(f1+'.txt', 'r') as fin1, open(f2+'.txt', 'r') as fin2:
          diff = difflib.ndiff(fin1.readlines(), fin2.readlines())
          outcome = ''.join(x[2:] for x in diff if x.startswith('- '))
          print outcome
  </code></pre>
  
  <p>How would i be able to achieve what i described above with tweaking this execution block?</p>
  
  <p>Note that both files share the same <code>frame</code> ammount but not the same <code>id</code>s so i would need to write two different files for each difference, possibly into a folder. So if the two files have 20 differences, i need to have two main folders one for each original file that each contain text files for every start and end <code>frame</code> of the same id.</p>