Trying to find a match in two strings - Python

Posted by Jacob Mammoliti on Stack Overflow See other posts from Stack Overflow or by Jacob Mammoliti
Published on 2013-10-31T21:44:33Z Indexed on 2013/10/31 21:54 UTC
Read the original article Hit count: 377

Filed under:
|

I have a user inputting two strings and then I want to check if there are any similar characters and if there is, get the position where the first similarity occurs, without using the find or index function.

Below is what I have so far but I doesn't fully work. With what I have so far, I'm able to find the similarities but Im not sure how to find the position of those similarities without using the index function.

string_a = "python"

string_b = "honbe"

same = []

a_len = len(string_a)
b_len = len(string_b)

for a in string_a:
    for b in string_b:

        if a == b:
            same.append(b)          

print (same)

Right now the output is:

['h', 'o', 'n']

So basically what I am asking is, how can I find the position of those characters without using the Python Index function?

© Stack Overflow or respective owner

Related posts about python

Related posts about python-3.x