I am trying to combine two programs that analyze strings into one program. The result should look at a parent string and determine if a sub-string has an exact match or a "close" match within the parent string; if it does it returns the location of this match
i.e. parent: abcdefefefef sub cde is exact and returns 2 sub efe is exact and returns 4, 6, 8 sub deg is close and returns 3 sub z has no match and returns None
The first program I wrote locates exact matches of a sub-string within a parent string:
import string
def subStringMatchExact():
print "This program will index the locations a given sequence"
print "occurs within a larger sequence"
seq = raw_input("Please input a sequence to search within: ")
sub = raw_input("Please input a sequence to search for: ")
n = 0
for i in range(0,len(seq)):
x = string.find(seq, sub, n, len(seq))
if x == -1:
break
print x
n = x + 1
The second analyzes whether or not there is an close match within a parent string and returns True if there is, and false if there isn't. Again a close match is an exact match or one that differs by only one character.
import string
def similarstrings():
print "This program will determine whether two strings differ"
print "by more than one character. It will return True when they"
print "are the same or differ by one character; otherwise it will"
print "return False"
str1 = raw_input("Enter first string:")
str2 = raw_input("Enter second string:")
x = 0
for i in range(len(str1)):
if str1[i] == str2[i]:
x = x + 1
else:
x = x
if x >= len(str1) - 1:
print True
else:
print False
Any suggestions on how to combine the two would be much appreciated.