Last active
September 17, 2022 12:24
-
-
Save Jawschamp/f541f742a2227dfb49ab5557c3cbe9e9 to your computer and use it in GitHub Desktop.
Get position of a character (clarity and testing purposes a 1 is added to each position)
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 char_pos_parser(parse_string: str, pattern: str): | |
char_dict = {} | |
char_array = [] | |
found_pat_array = [] | |
pos_array = [] | |
for i in enumerate(parse_string): | |
char_array.append(i) | |
for chars in char_array: | |
char_dict[chars[0]] = chars[1] | |
for key, value in char_dict.items(): | |
if value == pattern: | |
found_pat_array.append(value) | |
pos_array.append(key) | |
char_dict.clear() | |
for pos in pos_array: | |
for pat in found_pat_array: | |
char_dict[pos] = pat | |
return f"Found: '{pattern}' from: '{parse_string}' at: positions: {char_dict.keys()}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Some clean up will be made in a few days