Created
April 8, 2018 18:52
-
-
Save nickylimjj/e820292b8ae815ac467351eaf407ff94 to your computer and use it in GitHub Desktop.
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
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