I am making a function that translates normal strings into Braille characters.
To make the Braille dictionary, I create an empty braille_dictionary dictionary and then 2 functions addNumbers() and addLetters() to add keys and values to that dictionary:
def addNumbers(bd):
bd['1'] = [1, 0, 0, 0, 0, 0]
bd['2'] = [1, 1, 0, 0, 0, 0]
bd['3'] = [1, 0, 0, 1, 0, 0]
bd['4'] = [1, 0, 0, 1, 1, 0]
bd['5'] = [1, 0, 0, 0, 1, 0]
bd['6'] = [1, 1, 0, 1, 0, 0]
bd['7'] = [1, 1, 0, 1, 1, 0]
bd['8'] = [1, 1, 0, 0, 1, 0]
bd['9'] = [0, 1, 0, 1, 0, 0]
bd['0'] = [0, 1, 0, 1, 1, 0]
def addLetters(bd):
bd['a'] = [1, 0, 0, 0, 0, 0]
bd['b'] = [1, 1, 0, 0, 0, 0]
bd['c'] = [1, 0, 0, 1, 0, 0]
bd['d'] = [1, 0, 0, 1, 1, 0]
bd['e'] = [1, 0, 0, 0, 1, 0]
bd['f'] = [1, 1, 0, 1, 0, 0]
bd['g'] = [1, 1, 0, 1, 1, 0]
bd['h'] = [1, 1, 0, 0, 1, 0]
bd['i'] = [0, 1, 0, 1, 0, 0]
bd['j'] = [0, 1, 0, 1, 1, 0]
bd['k'] = [1, 0, 1, 0, 0, 0]
bd['l'] = [1, 1, 1, 0, 0, 0]
bd['m'] = [1, 0, 1, 1, 0, 0]
bd['n'] = [1, 0, 1, 1, 1, 0]
bd['o'] = [1, 0, 1, 0, 1, 0]
bd['p'] = [1, 1, 1, 1, 0, 0]
bd['q'] = [1, 1, 1, 1, 1, 0]
bd['r'] = [1, 1, 1, 0, 1, 0]
bd['s'] = [0, 1, 1, 1, 0, 0]
bd['t'] = [0, 1, 1, 1, 1, 0]
bd['u'] = [1, 0, 1, 0, 0, 1]
bd['v'] = [1, 1, 1, 0, 0, 1]
bd['x'] = [1, 0, 1, 1, 0, 1]
bd['y'] = [1, 0, 1, 1, 1, 1]
bd['z'] = [1, 0, 1, 0, 1, 1]
bd['w'] = [0, 1, 0, 1, 1, 1]
Here is my translator function:
def translator(string,braille_dict):
translated = []
wordList = string.split()
for i in wordList:
if i.lower() in braille_dict:
i = braille_dict[i]
translated.append(i)
if i.lower() not in braille_dict:
lst = []
for j in i:
if j in braille_dict:
j = braille_dict[j]
translated.append(j)
if j not in braille_dict:
j = []
translated.append(j)
return translated
The problem is that my function has done well with numbers and letters. For punctuation like question marks, I want to ignore, but my code returns the error: unhashable type: ‘list’
I will appreciate if you could help me solve this bug!