Exemplo n.º 1
0
def palindrom_finder():
    word_list = load_dict.load('2of4brif.txt')
    pali_list = []

    for word in word_list:
        if len(word) > 1 and word == word[::-1]:
            pali_list.append(word)

    print(f"\nNumber of palindromes found  = {len(pali_list)}")
    print(*pali_list, sep='\n')
Exemplo n.º 2
0
"""Find palindromes (letter palingrams) in a dictionary file."""
import load_dict
word_list = load_dict.load('dictionary.txt')
pali_list = []

for word in word_list:
    if len(word) > 1 and word == word[::-1]:
        pali_list.append(word)

print("\nTotal de palíndromos encontrados = {}\n".format(len(pali_list)))
print(*pali_list, sep='\n')
# *:  splat operator, which takes a list as input
# and expands it into positional arguments in the function call.
Exemplo n.º 3
0
import load_dict
word_list = load_dict.load('DIC.txt')
palin = []

for x in word_list:
    if len(x) > 1 and x == x[::-1]:
        palin.append(x)

print("no of palindromes = {}".format(len(palin)))
print(*palin, sep="\n")
Exemplo n.º 4
0
import sys
from collections import Counter
import load_dict

dict_file = load_dict.load('X')
dict_file = sorted(dict_file)

ini_name = input("Enter a name: ")
print(f'\nDEBUG: primer frase del usuario: {ini_name}\n')


def find_anagrams(name, word_list):
    name_letter_map = Counter(name)
    print(f'\nDEBUG: contador: {name_letter_map}\n')

    anagrams = []

    for word in word_list:
        test = ''
        word_letter_map = Counter(word.lower())
        for letter in word:
            if word_letter_map[letter] <= name_letter_map[letter]:
                test += letter
        if Counter(test) == word_letter_map:
            print(f'\nDEBUG: anagrama encontrado: {word_letter_map}\n')
            print(f'\nDEBUG: palabra agregada: {word}\n')

            anagrams.append(word)
    print(*anagrams, sep='\n')
    print()
    print("Letras restantes = {}".format(name))
Exemplo n.º 5
0
import load_dict
from collections import Counter
import sys

dict_file = load_dict.load("words.txt")
dict_file.append("a")
dict_file.append("i")
dict_file = sorted(dict_file)

ini_name = input("Enter a name : ")


def find_anagrams(name, word_list):
    name_letter_map = Counter(name)
    anagrams = []
    for word in word_list:
        test = ''
        word_letter_map = Counter(word.lower())
        for letter in word:
            if word_letter_map[letter] <= name_letter_map[letter]:
                test += letter
        if Counter(test) == word_letter_map:
            anagrams.append(word)
    print(*anagrams, sep='\n')
    print()
    print(f"Remaining letters = {name}")
    print(f"Number of remaining letters = {(len(name))}")
    print(f"Number of remaing (real world) anagrams : {(len(anagrams))}")


def process_choice(name):
Exemplo n.º 6
0
import string
import load_dict

input_message = "Ayuda fijarse bien"

message = ''

for char in input_message:
    if char in string.ascii_letters:
        # ascii_letters cotiene: 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
        message += char

print(message, "\n")
message = "".join(message.split())
print(message, "\n")

word_list = load_dict.load('X')

vocab_list = []
for letter in message:
    size = randint(6, 12)
    for word in word_list:
        if len(word) == size and word[0].lower() == letter.lower(
        ) and word not in vocab_list:
            vocab_list.append(word)
            break
if len(vocab_list) < len(message):
    print("El diccionario no es suficiente")
else:
    print("Vocabulario words for Unit 1: \n", *vocab_list, sep="\n")
Exemplo n.º 7
0
"""Find all word-pair palingrams in a dictionary file."""
import load_dict

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


def find_palingrams():
    """Find dictionary palingrams."""
    pali_list = []
    for word in word_list:
        end = len(word)
        rev_word = word[::-1]
        if end > 1:
            for i in range(end):
                if word[i:] == rev_word[:end -
                                        i] and rev_word[end - i:] in word_list:
                    pali_list.append((word, rev_word[end - i:]))
                if word[:i] == rev_word[end - i:] and rev_word[:end -
                                                               i] in word_list:
                    pali_list.append((rev_word[:end - i], word))
    return pali_list


if __name__ == "__main__":
    palingrams = find_palingrams()
    # sort on first word
    palingrams_sorted = sorted(palingrams)

    # display list of palingrams
    print(f"\nNumber of palingrams = {len(palingrams_sorted)}")
    for first, second in palingrams_sorted:
Exemplo n.º 8
0
import load_dict
import time

word_list = load_dict.load('palabras_todas.txt')

start_time = time.time()


def find_palingrams():
    pali_list = []
    for word in word_list:
        end = len(word)
        rev_word = word[::-1]
        if end > 1:
            for i in range(end):
                if word[i:] == rev_word[:end-i] and rev_word[end-i:] in word_list:
                    pali_list.append((word, rev_word[end-i:]))
                    # print(f'word[i:]: {word[i:]}')
                    # print(f'rev_word[:end-i]: {rev_word[:end-i]}')
                    # print(f'rev_word[end-i:]: {rev_word[end-i:]}')
                    # print(f'Palabra guardada: {word}, {rev_word[end-i:]}')

                if word[:i] == rev_word[end-i:]and rev_word[:end-i]in word_list:
                    pali_list.append((rev_word[:end-i], word))

    return pali_list


end_time = time.time()

palingrams = find_palingrams()