title: Print lines when Last digit of two files are same
body: <p>I have a file1</p>
  <pre><code>AI21T A1,A2,B,Zn |3
  AN3DT A1,A2,Z |2
  AO22T A1,A2,B,Z |3
  BUFF1 I,Z |1
  </code></pre>
  <p>and file2 as</p>
  <pre><code>AO22T A1,A2,B,Z |3
  </code></pre>
  <p>I want to compare last digit of file2 with last digit of file1 and if matches then print that match line from file1 in fout file.
  The output should be fout</p>
  <pre><code>AI21T A1,A2,B,Zn |3
  AO22T A1,A2,B,Z |3
  </code></pre>
  <p>I tried the code</p>
  <pre><code>
  f1=open(&quot;file1&quot;,&quot;r&quot;)
  f2=open(&quot;file2&quot;,&quot;r&quot;)
  fo=open(&quot;fout&quot;,&quot;w&quot;)
    for line1 in f1:
       l1=line1.strip()
       for line2 in f2:
          l2=line2.strip()
          if l1[-1:].isdigit()==l2[-1:].isdigit():
             data=f1.readlines()
     print &gt;&gt; fo,data
  </code></pre>
  <p>But I am getting error while comparing and writing in file.</p>