Get word mappings to strings of numbers
mappings = {
'0': ' ',
'1': ' ',
'2':'ABC',
'3':'DEF',
'4':'GHI',
'5':'JKL',
'6':'MNO',
'7':'PQRS',
'8':'TUV',
'9':'WXYZ'
}
so 2255 might get "ball" :)
# Crosscompute
number_string_count = 2255
target_folder = '/tmp'
import numpy as np
from itertools import product
from os.path import join
dictionary_text_path = 'dictionary.txt'
mappings = {
'0': ' ',
'1': ' ',
'2':'ABC',
'3':'DEF',
'4':'GHI',
'5':'JKL',
'6':'MNO',
'7':'PQRS',
'8':'TUV',
'9':'WXYZ'
}
number = str(number_string_count)
dictionary = set()
with open(dictionary_text_path, 'r') as f:
for l in f:
dictionary.add(l.strip().lower())
ll = (mappings.get(x, '') for x in number)
permutations = set((''.join(x)).lower() for x in product(*ll))
possible_words = list(permutations & dictionary)
if len(possible_words) > 0:
possible_words_text_path = join(target_folder, 'possible_words.txt')
with open(possible_words_text_path, 'w') as f:
f.writelines(x + '\n' for x in possible_words)
print('possible_words_text_path = %s' % possible_words_text_path)
all_mappings_text_path = join(target_folder, 'all_mappings.txt')
with open(all_mappings_text_path, 'w') as f:
for l in permutations:
f.write
f.writelines(x + '\n' for x in permutations)
print('all_mappings_text_path = %s' % all_mappings_text_path)