Skip to content

Instantly share code, notes, and snippets.

@luanbe
Created September 16, 2021 10:10
Show Gist options
  • Select an option

  • Save luanbe/67b517d12c2c83ebb0b5d706e1719cae to your computer and use it in GitHub Desktop.

Select an option

Save luanbe/67b517d12c2c83ebb0b5d706e1719cae to your computer and use it in GitHub Desktop.
Python utils
def find_subs(s1, s2):
subs = []
loc = 0
while s1:
s1_copy = s1
while s1_copy:
while s1_copy and s1_copy not in s2:
s1_copy = s1_copy[:-1]
if s1_copy:
subs.append((loc, s2.index(s1_copy), s1_copy))
loc += len(s1_copy)
s1 = s1[len(s1_copy):]
else:
s1 = s1[1:]
loc += 1
s1_copy = s1
return subs
str1 = "ABCDEPQRUVWXYZ" # added extra non-matching character
str2 = "PQRABCDUVWXYZ"
print(find_subs(str1, str2))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment