0

I've been experimenting with itertools, combinations and enchant to find all possible (English) words from a list of characters, up to a set (x) amount of words, with no character limit for each word. Can't seem to find/create what I am looking for. Not looking for a handout or freebie, just genuinely stuck on a DnD cipher my friend passed along to me.

Basically, if I have:
char_list = ['i', 't', 'c', 'r', 'r', 's', 'f', 'o', 'k', 'p', 'a', 'e', 'u', 'a']

I'm trying to print:
possible_combos = [["xxx", "xxx", "xxx", "xxx"], ...]

Please don't laugh, but this is what I've been working with. I know it's not right, but I'm having a really hard time understanding exactly what I'm missing.

import itertools

lst = ['i', 't', 'c', 'r', 'r', 's', 'f', 'o', 'k', 'p', 'a', 'e', 'u', 'a']
combinatorics = itertools.product([True, False], repeat=len(lst) - 1)

solution = []
for combination in combinatorics:
    i = 0
    one_such_combination = [lst[i]]
    for slab in combination:
        i += 1
        if not slab:  # there is a join
            one_such_combination[-1] += lst[i]
        else:
            one_such_combination += [lst[i]]
    solution.append(one_such_combination)

print(solution)
  • You want every permutation of the full list? If so, does that include sub-lists? – Mike67 Aug 23 '20 at 20:24
  • No sub-lists, just every permutation of a list of four real words. It doesn't have to be in any specific format or anything, I just concatenated the above example for simplicity. – Joseph Julian Aug 23 '20 at 20:40

0 Answers0