Skip to content

Instantly share code, notes, and snippets.

@Jawschamp
Last active September 17, 2022 12:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Jawschamp/f541f742a2227dfb49ab5557c3cbe9e9 to your computer and use it in GitHub Desktop.
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)
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()}"
@Jawschamp
Copy link
Author

Some clean up will be made in a few days

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment