Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2019
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.52 KB | None | 0 0
  1. #https://programmingpraxis.com/2019/06/21/string-comparison/
  2.  
  3. def clean(word):
  4.     for i in word:
  5.         if i == '#':
  6.             if word.index(i) == 0:
  7.                 word = word[1:]
  8.             else:
  9.                 word = word[0:word.index(i)-1] + word[word.index(i)+1:]
  10.     return word
  11.  
  12. def hashCompare(word1,word2):
  13.     word2 = clean(word2)
  14.     word1 = clean(word1)
  15.     if word1 == word2:
  16.         return True
  17.     else:
  18.         return False
  19.        
  20. print(str(hashCompare("abcde","abcx#de"))) #true
  21. print(str(hashCompare("#abc##","1#234###a"))) #true
  22. print(str(hashCompare("ab","aa"))) #false
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement