Exemplo n.º 1
0
def dict_of_char_in_anagram_sentence(anagram_sentence):
    dictionary_of_chars = dict()
    for char in utility.remove_space_from_sentence(anagram_sentence):
        dictionary_of_chars[char] = value_to_increment_to_in_dict(
            dictionary_of_chars, char)

    return dictionary_of_chars
def get_sorted_list_tuple_char_to_prime(list_of_words,
                                        anagram_sentence="poultryoutwitsants"):
    anagram_sentence = utility.remove_space_from_sentence(anagram_sentence)
    dict_prime_char = dict_prime_numbers_to_anagram_character(anagram_sentence)

    dict_word_prime_sums = dict_words_to_prime_product_sums(
        list_of_words, dict_prime_char)

    sorted_dict = utility.get_sorted_list_of_tuple_from_dict(
        dict_word_prime_sums)

    return sorted_dict
def dict_prime_numbers_to_anagram_character(anagram_sentence):
    dict_of_prime_number_mapping = dict()
    set_of_characters_in_anagram = set(
        utility.remove_space_from_sentence(anagram_sentence))

    # Converting to list to avoid random enumeration of set.
    list_of_character_in_anagram = list(set_of_characters_in_anagram)
    list_of_character_in_anagram = sorted(list_of_character_in_anagram)

    list_of_prime_numbers = prime_numbers.get_list_of_prime_numbers()

    for index, character in list(enumerate(list_of_character_in_anagram)):
        dict_of_prime_number_mapping[character] = list_of_prime_numbers[index]

    return dict_of_prime_number_mapping
Exemplo n.º 4
0
def remove_words_with_invalid_char(list_of_words, anagram_sentence):
    set_of_character_in_anagram = set()
    list_of_clean_words = []

    for char in utility.remove_space_from_sentence(anagram_sentence):
        set_of_character_in_anagram.add(char)

    for word_in_file in utility.remove_empty_space_in_list(list_of_words):
        for char in word_in_file:
            if char not in set_of_character_in_anagram:
                break
        else:
            # This happens if for loop is run without the break
            list_of_clean_words.append(word_in_file)
            continue

    return list_of_clean_words
Exemplo n.º 5
0
def remove_words_with_too_many_of_one_char(list_of_words, anagram_sentence):
    list_of_clean_words = []
    d = dict_of_char_in_anagram_sentence(
        utility.remove_space_from_sentence(anagram_sentence))

    for word in utility.remove_empty_space_in_list(list_of_words):
        dict_current_word = dict()
        for char in word:
            dict_current_word[char] = value_to_increment_to_in_dict(
                dict_current_word, char)
            if dict_current_word[char] > d[char]:
                break
        else:
            list_of_clean_words.append(word)
            continue

    return list_of_clean_words
def prime_product_sum_of_anagram_sentence(anagram_sentence,
                                          dict_char_to_prime):
    product_sum = 1
    for character in utility.remove_space_from_sentence(anagram_sentence):
        product_sum *= dict_char_to_prime[character]
    return product_sum
Exemplo n.º 7
0
def test_remove_space_from_sentence():
    sentence = "hello test world"
    expected = "hellotestworld"
    result = utility.remove_space_from_sentence(sentence)
    assert expected == result