title: Counting common characters between two strings in python
body: <p>I have a code I've been working on, but it doesn't output as well as I need it to. I had to make up my own algorithm for a code in python that counts characters in input strings. It is like haystack in a needle method but I'm not supposed to use any text comparing methods, like count() and findall(). I would like my code to count character by character and doesn't count overlapping letters. I'm looking for longest common substring. Here is my code so far, but it outputs still wrong. When I type "aaaaa" in the String1 field and "aa" in the String 2 field, it outputs 1, but it should output 2, because there are 2 "aa"s in the "aaaaa" without overlapping.</p>
  
  <pre><code>    test1 = input("String1: ")
      test2 = input("String2: ")
  
      common = {}
      if len(test1)&lt;len(test2):
      for letter in test1:
          if letter in test2:
              common[letter]= 1
  
      else:
      for letter in test2:
          if letter in test1:
              common[letter]= 1
      print (len(common))
  </code></pre>