Question: Write a PYTHON code to convert 'a word' to a horizontal matrix and then convert the horizontal matrix to 'word'. 1) Create an encode() function

Write a PYTHON code to convert 'a word' to a horizontal matrix and then convert the horizontal matrix to 'word'.

1) Create an encode() function to that takes a word as input and prints a matrix representation

Write a PYTHON code to convert 'a word' to a horizontal matrix

Each letter in the word can be represented as a 3 2 matrix (convert each letter from dict format to horizontal matrix)

In case of multiple letters, the encode() function must represent the word by simply concatenating the matrices horizontally.

For example:

"a": [[1, 1], [0, 0], [0, 0]]

"b": [[1, 1], [1, 0], [0, 0]]

"c": [[1, 0], [0, 0], [0, 0]]

and then convert the horizontal matrix to 'word'. 1) Create an encode()

If the input is 'abc', the output will be:

function to that takes a word as input and prints a matrix

2) Create an translate() function to that takes name of a txt file containing the matrix text as input and prints a word.

representation Each letter in the word can be represented as a 3

For examples, read the matrix in the data.txt and then translate it to a word using the translate_table() above.

Input: data.txt containing matrix below:

2 matrix (convert each letter from dict format to horizontal matrix) In

Output: abc

For the simplification, data.txt file will only contain 1 word and all lowercase letters.

1 - def encode_table (): 2 3- dict = { 4 "a": [[1, 1], [0, 0], [0, 0]], 5 "b": [[1, 1], [1, 0], [0, 0]], 6 "C": [[1, 0], [0, 0], [0, 0]], 7 "d": [[1, 0], [0, 1], [0, 0]], 8 "e": [[1, 1], [0, 1], [0, 0]], 9 "f": [[1, 0], [1, 0], [0, 0]] 10 } 11 12 return dict w 00 OU A 12 1 1 1 1 1 0 0 0 1 0 0 0 OOOOOO albc 1 1 1 1 1 0 0 0 1 0 0 0 eeeeee 1 - def translate_table (): 2 3- translate = { 4 "110000": "a", 5 "111000": "b", 6 "100000": "C", 7 "100100": "d", 8 "110100": "e", 9 "101000": "f" 10 } 11 12 return translate vou AWN 1 1 1 1 1 0 0 0 1 0 0 0 eeeeee

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!