Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #https://programmingpraxis.com/2019/06/21/string-comparison/
- def clean(word):
- for i in word:
- if i == '#':
- if word.index(i) == 0:
- word = word[1:]
- else:
- word = word[0:word.index(i)-1] + word[word.index(i)+1:]
- return word
- def hashCompare(word1,word2):
- word2 = clean(word2)
- word1 = clean(word1)
- if word1 == word2:
- return True
- else:
- return False
- print(str(hashCompare("abcde","abcx#de"))) #true
- print(str(hashCompare("#abc##","1#234###a"))) #true
- print(str(hashCompare("ab","aa"))) #false
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement