title: Function to find all common substrings in two strings not giving correct output
body: <p>I am using the following function to find all the common substrings between two strings:</p>
  
  <pre><code>def substringFinder(string1, string2):
      answer = ""
      anslist=[]
      len1, len2 = len(string1), len(string2)
      for i in range(len1):
          match = ""
          for j in range(len2):
              if (i + j &lt; len1 and string1[i + j] == string2[j]):
                  match += string2[j]
                  j=j+1
              else:
                  #if (len(match) &gt; len(answer)): 
                  answer = match
                  if answer != '':
                      anslist.append(answer)
                  match = ""
  
          if match != '':
              anslist.append(match)
          break
      print(anslist)
  </code></pre>
  
  <p>So when I do <code>substringFinder("ALISSA", "ALYSSA")</code> is gives <code>['AL', 'SSA']</code> which is fine. But when I do <code>substringFinder("AHAMMAD", "AHAMAD")</code>, it only gives output <code>['AHAM']</code> but I want <code>['AHAM', 'MAD']</code> as output. How to get that?</p>