title: Calculate the greatest distance between any two strings in a group, using Python
body: <p>My question is how to calculate greatest distance between any two strings that correspond to a certain group. Each line in my file starts with a 'group number' followed by a long string. I want to know, for each group, what the greatest distance between any two strings in a group, for each group. Below is the kind of file I'm working with (the strings have been shortened). Notice the groups aren't necessarily in order, and some of my groups only have one string associated with them, so I would want to just skip over them (Group '3' in the below example):</p>
  
  <pre><code> 0 GCAGACGGGUGAGUAACGCGUGGGAACGUACCAUUUGCUACGGAAUAACUCAGG
   0 GCAGACGGGUGAGUAACGCGUGGGAACGUACCAUUUGCUACGGAAUAACUCAGG
   1 CGAACGGGUGAGUAACACGUGGGCAAUCUGCCCUGCACUCUGGGACAAGCCCUG
   1 CGAACGGGUGAGUAACACGUGGGCAAUCUGCCCUGCACUCUGGGACAAGCCCUG
   1 CGAACGGGUGAGUAACACGUGGGCAAUCUGCCCUGCACUCUGGGACAAGCCCUG
   2 GCCCUUCGGGGUACUCGAGUGGCGAACGGGUGAGUAACACGUGGGUGAUCUGCC
   2 GCCCUUCGGGGUACUCGAGUGGCGAACGGGUGAGUAACACGUGGGUGAUCUGCC
   2 GCCCUUCGGGGUACUCGAGUGGCGAACGGGUGAGUAACACGUGGGUGAUCUGCC
   0 GCAGACGGGUGAGUAACGCGUGGGAACGUACCAUUUGCUACGGAAUAACUCAGG
   0 GCAGACGGGUGAGUAACGCGUGGGAACGUACCAUUUGCUACGGAAUAACUCAGG
   3 GCAGACGGGUGAGUAACAAAAAGGAACGUACCAUUUGCUACGGAAUAACUCAGG
  </code></pre>
  
  <p>I want to create something that will create an output that looks something like this: </p>
  
  <pre><code> Group0 = 0
   Group1 = 1.2
   Group2 = 2.1
  
   Average = 1.1
  </code></pre>
  
  <p>This output would be giving me the group number and then the greatest difference for that group. And also the overall average of the greatest difference between all groups (again skipping over the groups with only one string associated with them):</p>
  
  <p>My real file has about 5000 groups, and the strings I'm comparing are ~400 characters long.</p>
  
  <p>I think I could start solving this by looking at this <a href="https://stackoverflow.com/questions/3106994/algorithm-to-calculate-percent-difference-betweem-two-blobs-of-text">Question</a>, but I'm not sure how to only calculate percent differences for strings in the same group, avoid groups with only one string, and calculate the overall average percent difference for all the groups. Any help would be greatly appreciated, thank you very much for any ideas!  </p>
  
  <p>EDIT: Here are a few truncated lines from the file I'm working with. The 'group' numbers range from 0 to ~ 6000. The string of letters is actually 426 characters long. The file format is [number][a whitespace][string of letters][end of line character]</p>
  
  <p><code>7 UGGCGAACGGGUGAGUAAC<br>
  35 GUGGGGAUUAGUGGCGAAC<br>
  50 AAACGAGAUGUAGCAAUAC<br>
  82 GGAGAGAGCUUGCUCUCUU<br>
  479 UCAGGAGCUUGCUCCUGU<br>
  46 CGAGGAGCUUGCUCCUUU<br>
  24 AACUGGGUCUAAUACCUU</code>     </p>