Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- BREAK = "|"
- break_charactors = ["_", "-", " "]
- def eq(string1, string2):
- # I think we can look through the different cases that we have here
- # So cleary string1===string2 => True
- if string1==string2:
- return True
- # But then we want to use more inteligence to work out what we are dealing with
- # I think the next thing we should do is to beak the text appart into numeric, symbolic and alphabetical, keeping the order
- if break_down(string1) == break_down(string2):
- return True
- if break_down(string1).replace(BREAK, "") == break_down(string2).replace(BREAK, ""):
- return True
- print(break_down(string1))
- print(break_down(string2))
- return False
- def xor(b1, b2):
- return bool(b1) != bool(b2)
- def issymbol(char):
- return not (char.isalnum() or char in break_charactors)
- def break_down(string):
- # I would say we have a few classes here
- #divider type \s _ \l\u a break from alphabetical
- #alphabetical
- #symbolic
- #numeric
- acc = ""
- for last_char, this_char in zip(BREAK + string[:-1],string):
- # what we want here is if the previous char was upper and this is lower to create a break
- if last_char.islower() and this_char.isupper():
- #insert a break before this char
- acc += BREAK + this_char.lower()
- continue
- if last_char in break_charactors:
- acc += BREAK + this_char
- continue
- # might want to condition this on is alphanumeric
- if last_char.isalnum() and this_char.isalnum() and xor(last_char.isnumeric(), this_char.isnumeric()):
- acc += BREAK + this_char
- continue
- if this_char.isalnum():
- acc += this_char
- return acc.lower()
Advertisement
Add Comment
Please, Sign In to add comment