combinations

 Pay Notebook Creator: Salah Ahmed 0 Set Container: Numerical CPU with TINY Memory for 10 Minutes 0 Total 0

telephone¶

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" :)

In :
# Crosscompute
number_string_count = 2255
target_folder = '/tmp'

In :
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'
}

In :
number = str(number_string_count)
dictionary = set()
with open(dictionary_text_path, 'r') as f:
for l in f:

In :
ll = (mappings.get(x, '') for x in number)
permutations = set((''.join(x)).lower() for x in product(*ll))
possible_words = list(permutations & dictionary)

In :
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)

possible_words_text_path = /tmp/possible_words.txt

In :
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)

all_mappings_text_path = /tmp/all_mappings.txt