### clarify palindrome checks

master
Charles Reid преди 2 години
родител
ревизия
907676dd82
променени са 2 файла, в които са добавени 16 реда и са изтрити 10 реда
1. +11
-7
near_palindromes.py
2. +5
-3
palindromes.py

#### + 11 - 7 near_palindromes.pyЦелия файл

 @@ -11,11 +11,13 @@ from get_words import get_words from euclidean_distance import euclidean_distance from pprint import pprint def is_near_palindrome(word,tol): test1 = euclidean_distance(word[0],word[4])<=tol test2 = euclidean_distance(word[1],word[3])<=tol if(test1 and test2): def is_near_palindrome(word,lo,hi): d1 = euclidean_distance(word[0],word[4]) d2 = euclidean_distance(word[1],word[3]) if( (d1+d2) > lo and (d1+d2) <= hi ): return True return False if __name__=="__main__": @@ -25,14 +27,16 @@ if __name__=="__main__": near_palindromes = [] # Euclidean distance tolerance tol = 2.0 lo = 0.0 hi = 1.0 for i in range(len(words)): if(is_near_palindrome(words[i],tol)): if(is_near_palindrome(words[i],lo,hi)): knp += 1 near_palindromes.append(words[i]) print("-"*40) print("Near Palindromes: \n") pprint(near_palindromes) print(", ".join(near_palindromes)) print("The number of near-palindromes is {0:d}".format(len(near_palindromes)))

#### + 5 - 3 palindromes.pyЦелия файл

 @@ -44,7 +44,8 @@ if __name__=="__main__": print("-"*40) print("Palindromes: \n") pprint(palindromes) print(", ".join(palindromes)) print("There are {0:d} palindromes.".format(kp)) # Check for palindrome pairs for i in range(len(words)): @@ -57,5 +58,6 @@ if __name__=="__main__": print("-"*40) print("Palindrome Pairs: \n") pprint(palindrome_pairs) for pair in palindrome_pairs: print(", ".join(pair)) print("There are {0:d} palindrome pairs.".format(kpp))