Telling the length of the highest common substring between 2 words This takes two strings and returns the length of the largest common substring.

Example:

contando_sstring_igual("abcdef", "cdofhij")
# 2


Because the longest common substring = "cd", so it returns the length of it (2).

Here is the code:

def contando_sstring_igual(string1, string2):
    resposta = ""
    tamanho1 = len(string1)
    tamanho2 = len(string2)
    for i in range(tamanho1):
        for j in range(tamanho2):
            lcs_temp = 0
            igual = ''
            while i + lcs_temp &lt; tamanho1 and j + lcs_temp &lt; tamanho2 and string1[i + lcs_temp] == string2[j + lcs_temp]:
                igual += string2[j+lcs_temp]
                lcs_temp += 1
            if len(igual) &gt; len(resposta):
                resposta = igual
    return len(resposta)


while True:
    a = input()
    b = input()
    if a is None or b is None:
        break
    else:
        print(contando_sstring_igual(a, b))


I need to make my code work significantly faster. It does the job right, but not fast enough. I need to avoid the timeout error I'm getting on the exercise and I'm not even close to figuring out how to do it, without the loop.
English please!

Identifiers and comments reallly really should be in English for all code you write.  Otherwise it will be hard to impossible to take part in the completely globalized IT world we're living in.

Break long lines

Your lines shouldn't be longer than 79 characters.  Break them before binary operators:

while i + lcs_temp &lt; tamanho1 \
      and j + lcs_temp &lt; tamanho2 \
      and string1[i + lcs_temp] == string2[j + lcs_temp]:




performance related comments still under construction ;)

Ok, I got a bit hooked up here, and I think I've got something usable out of it.  I'm though not yet posting the code as it's late here and currently really a mess, so I'll tidy up tomorrow and post it then.  

Teaser (ignore the x-axis label):



Code for measurement, though killed after size 100 due to long runtime:

for size in chain(range(10, 100, 10), range(100, 1000, 100)):
    times = map(lambda v: timeit('lcsl_{}("abcdef" * {}, "cdofhij" * {})'.format(v, size, size),
                                 globals=globals(),
                                 setup='gc.collect(); gc.enable()',
                                 number=10),
                ('danieljour', 'mateus', 'aries', 'reti'))
    print(size, '\t', '\t'.join(map(str, times)))