"""Find all word pair palingrams in a dictionary file."""
import time

import load_diction

word_list = load_diction.load('2of4brif.txt')


#find word pair palingrams
def find_palingrams():
    """Find dictionary palingrams"""
    pali_list = []
    for word in word_list:
        end = len(word)
        rev_word = word[::
                        -1]  #word.join(reversed(word)) produces different result, not sure why
        if end > 1:
            for i in range(end):
                if word[i:] == rev_word[:end -
                                        1] and rev_word[end - 1:] in word_list:
                    pali_list.append((word, rev_word[end - 1:]))
                if word[:i] == rev_word[end - 1:] and rev_word[:end -
                                                               i] in word_list:
                    pali_list.append((rev_word[:end - 1], word))
    return pali_list


start_time = time.time()
palingrams = find_palingrams()
end_time = time.time()
#sort palingrams alphabetically
Beispiel #2
0
import load_diction

word_list = load_diction.load("2of4brif.txt")

anagram_list = []

name = input("Enter a word or name ")
print("Input name = {}".format(name))
name = name.lower()
print("Using name = {}".format(name))

# sort name & find anagrams
name_sorted = sorted(name)
for word in word_list:
    word = word.lower()
    if word != name:
        if sorted(word) == name_sorted:
            anagram_list.append(word)

# print anagram
print()
if len(anagram_list) == 0:
    print("You need a larger dictionary or a new name!")
else:
    print("Anagrams =", *anagram_list, sep='\n')