Skip to content

Instantly share code, notes, and snippets.

@nickylimjj
Created April 8, 2018 18:52
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 nickylimjj/e820292b8ae815ac467351eaf407ff94 to your computer and use it in GitHub Desktop.
Save nickylimjj/e820292b8ae815ac467351eaf407ff94 to your computer and use it in GitHub Desktop.
m = {}
def foo(regex, s_list):
for idx, token in enumerate(regex):
# set token and ensure unique values
if (token not in m and
s_list[idx] not in m.values()):
m[token] = s_list[idx]
# fails if token not added (bcoz substring not unique) or
# token already has a substring
if (token not in m or
m[token] != s_list[idx]):
return False
return True
while (True):
regex = input("regex:")
s = input("s:")
s_list = s.split(" ")
res = foo(regex, s_list)
print(res)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment