Created
September 16, 2021 10:10
-
-
Save luanbe/67b517d12c2c83ebb0b5d706e1719cae to your computer and use it in GitHub Desktop.
Python utils
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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