title: Comparing two words from different lines in a file using python
body: <p>I am working with a file from the protein data bank which looks something like this.</p>
  
  <pre><code>SITE     2 AC1 15 ASN A 306  LEU A 309  ILE A 310  PHE A 313                    
  SITE     3 AC1 15 ARG A 316  LEU A 326  ALA A 327  ILE A 345                    
  SITE     4 AC1 15 CYS A 432  HIS A 435  HOH A 504                               
  CRYST1   64.511   64.511  111.465  90.00  90.00  90.00 P 43 21 2     8          
  ORIGX1      1.000000  0.000000  0.000000        0.00000                         
  ORIGX2      0.000000  1.000000  0.000000        0.00000                         
  ORIGX3      0.000000  0.000000  1.000000        0.00000                         
  SCALE1      0.015501  0.000000  0.000000        0.00000                         
  SCALE2      0.000000  0.015501  0.000000        0.00000                         
  SCALE3      0.000000  0.000000  0.008971        0.00000                         
  ATOM      1  N   ASP A 229      29.461  51.231  44.569  1.00 47.64           N  
  ATOM      2  CA  ASP A 229      29.341  51.990  43.290  1.00 47.13           C  
  ATOM      3  C   ASP A 229      30.455  51.566  42.330  1.00 45.62           C  
  ATOM      4  O   ASP A 229      31.598  51.376  42.743  1.00 47.18           O  
  ATOM      5  CB  ASP A 229      29.433  53.493  43.567  1.00 49.27           C  
  ATOM      6  CG  ASP A 229      28.817  54.329  42.463  1.00 51.26           C  
  ATOM      7  OD1 ASP A 229      27.603  54.172  42.206  1.00 53.47           O  
  ATOM      8  OD2 ASP A 229      29.542  55.145  41.856  1.00 52.96           O  
  ATOM      9  N   MET A 230      30.119  51.424  41.051  1.00 41.99           N  
  ATOM     10  CA  MET A 230      31.092  51.004  40.043  1.00 36.38           C  
  </code></pre>
  
  <p>First I needed to extract only the fourth column of the rows labeled ATOM, which is the amino acid sequence that specific atom is a part of. I have done that here.</p>
  
  <pre><code>import gzip
  class Manual_Seq:
  
      def parseSeq(self, path):
          with gzip.open(path,'r') as file_content:
              for line in file_content:
                  newLine = line.split(' ')[0]
                  if newLine == 'ATOM':
                      AA = line[17]+line[18]+line[19]
                      print AA
  </code></pre>
  
  <p>Which produces an output of this </p>
  
  <pre><code>ASP
  ASP
  ASP
  .....
  MET
  </code></pre>
  
  <p>But what I need now, is to output only the first ASP and the first MET and etc and concatenate them so it'll look like this. </p>
  
  <pre><code>ASPMET
  </code></pre>
  
  <p>I was thinking maybe I'll try to iterate ahead one line and compare it until it is different from the first output, but I am unsure of how I would do this, if you have any other ideas or any improvements to my code please do feel free to submit your suggestions, thanks.
  I also need to mention that there can in fact be two identical amino acids in one file so the output could be "ASP MET ASP"</p>