character sequence

unlisted ⁨1⁩ ⁨file⁩ 2019-06-16 03:21:06 UTC

character_sequence.py

Raw
import itertools

# this function takes a dictionary and returns a dictionary whose keys are sequences of keys of the original dictionary
# and whose values our the corresponding sequences of values of the original dictionary
def make_sequence_dict_fixed_length(dictionary, fixed_sequence_length):
    mapping = {}
    for tup in itertools.product(dictionary.keys(), repeat=fixed_sequence_length):
        mapping[" ".join(tup)] = "".join(dictionary[word] for word in tup)
    return mapping


def make_sequence_dict_up_to_length(dictionary, highest_length):
    # d will be a dict of whole number keys pointing to the corresponding fixed length dictionaries
    d = {}
    for i in range(1, highest_length + 1):
        d[i] = make_sequence_dict_fixed_length(dictionary, i)
    # output = {k: d[i][k] for k in d[i] for i in d}
    output = {}
    for i in d:
        for k in d[i]:
            output[k] = d[i][k]
    return output



text_punc_dict.update(caster_alphabet)
character_dict = text_punc_dict
character_sequence_dict = make_sequence_dict_up_to_length(character_dict, 2)
character_sequence_list = character_sequence_dict.values()