title: Python code to read first 14 characters, uniquefy based on them, and parse duplicates
body: <p>I have a list of more than 10k os string that look like different versions of this (HN5ML6A02FL4UI_3 [14 numbers or letters_1-6]), where some are duplicates except for the _1 to _6.  </p>
  
  <p>I am trying to find a way to list these and remove the duplicate 14 character (that comes before the _1-_6).</p>
  
  <p>Example of part of the list:</p>
  
  <p><code>HN5ML6A02FL4UI_3</code></p>
  
  <p><code>HN5ML6A02FL4UI_1</code></p>
  
  <p><code>HN5ML6A01BDVDN_6</code></p>
  
  <p><code>HN5ML6A01BDVDN_1</code></p>
  
  <p><code>HN5ML6A02GVTSV_3</code></p>
  
  <p><code>HN5ML6A01CUDA2_1</code></p>
  
  <p><code>HN5ML6A01CUDA2_5</code></p>
  
  <p><code>HN5ML6A02JPGQ9_5</code></p>
  
  <p><code>HN5ML6A02JI8VU_1</code></p>
  
  <p><code>HN5ML6A01AJOJU_5</code></p>
  
  <p>I have tried versions of scripts using Reg Expressions: <code>var n = /\d+/.exec(info)[0];</code> into the following that were posted into my previous question. and </p>
  
  <p>I also used a modified version of the code from : <a href="https://stackoverflow.com/questions/17174528/how-can-i-strip-the-first-14-characters-in-an-list-element-using-python">How can I strip the first 14 characters in an list element using python?</a></p>
  
  <p>More recently I used this script and I am still not getting the correct output.</p>
  
  <pre><code>import os, re
  
  def trunclist('rhodopsins_play', 'hope4'):
      with open('rhodopsins_play','r') as f:
          newlist=[]
          trunclist=[]
          for line in f:
              if line.strip().split('_')[0] not in trunclist:
                  newlist.append(line)
                  trunclist.append(line.split('_')[0])
      print newlist, trunclist
  
      # write newlist to file, with carriage returns
      with open('hope4','w') as out:
          for line in newlist:
              out.write(line)
  </code></pre>
  
  <p>My <em>inputfile.txt</em> contains more than 10k of data which looks like the list above, where the important part are the characters are in front of the '_' (underscore), then outputting a file of the uniquified <code>ABCD12356_1</code>.</p>
  
  <p>Can someone help?</p>
  
  <p>Thank you for your help</p>