title: Python: matching values from one list to the sequence of values in another list
body: <p>Really need help.  I've confused myself with loops and hit a brick wall.</p>
  
  <p>I have two lists.</p>
  
  <pre><code> e_list = [('edward', '1.2.3.4.'), ('jane','1.2.3.4.'), ('jackie', '2.3.4.10.')...]
  </code></pre>
  
  <p>and a_list (the main list to be checked against)</p>
  
  <pre><code> a_list = [('a', '1.2.3.'), ('b', '2.3.'), ('c', '2.3.4.')...]
  </code></pre>
  
  <p>My problem: I want to match the digits in the numbers in <em>e_list</em> to the shortest sequence of the numbers in <em>a_list</em>.  So that <em>new_list</em> is formed to look like:</p>
  
  <pre><code> new_list = [ ('edward', '1.2.3.4', '1.2.3'), ('jane', '1.2.3.4.', '1.2.3'), ('jackie', '2.3.4.10.', '2.3.')...]
  </code></pre>
  
  <p>What I've currently done (not much, I know) is:</p>
  
  <pre><code>for e in e_list:
      e_key = e[1]
      for a in a_list:
          a_key = a[1]
          if a_key in e_key:
              print a_key, "in"
  </code></pre>
  
  <p>What this is doing is checking if the numbers of <em>a_list</em> are in those of <em>e_list</em>.  But then it's printing out "in" for all sequences e.g. jackie is counted as in for both b and c, whereas I want it to be the shortest value, b.  I'm struggling now with what the next step is.  Any help would be appreciated.  Thankyou in advance.</p>