In the JetBrains Mono1 font, letter E is written with 4 straight lines, letter R with 2 straight and 1 curved line, letter G with 1 straight and 1 curved line, and letter O with 1 curved line. In that font, all letters of the word ERGONOMICS are written with 17 straight and 6 curved lines.

ERGONOMICS
In the JetBrains Mono font, the word ERGONOMICS is written with 17 straight lines and 6 curved lines.
ERGONOMICS
In the JetBrains Mono font, the word ERGONOMICS is written with 17 straight lines and 6 curved lines.

In the JetBrains Mono font, all letters of the word SUDOKU are written with 5 straight lines and 5 curved lines.

SUDOKU
In the JetBrains Mono font, the word SUDOKU is written with 5 straight lines and 5 curved lines.
SUDOKU
In the JetBrains Mono font, the word SUDOKU is written with 5 straight lines and 5 curved lines.

Assignment

A font description is stored in a text file. Each line of the file contains three space-separated fields: i) a single character, ii) the number of straight lines in the character and iii) the number of curved lines in the character. Each character appears at most once in the file.

For example, this file describes all uppercase letters of the JetBrains Mono font (font.txt2):

A 3 0
B 1 2
C 0 1
D 1 1
E 4 0
…
X 2 0
Y 3 0
Z 3 0

Your task:

A dictionary $$\mathcal{F}$$ (dict) that is passed as a second argument to the functions count_straight_lines, count_curved_lines, straight_lines_only, curved_lines_only and balanced_lines must be formatted as the dictionaries returned by the function read_font. In counting lines, these function must only take into account characters in word $$w$$ that appear as keys in dictionary $$\mathcal{F}$$. Other characters of word $$w$$ must be ignored. These functions must also make a distinction between uppercase and lowercase letters.

Example

In the following interactive session we assume the text files font.txt3 and dictionary.txt4 to be located in the current directory.

>>> font = read_font('font.txt5')
>>> font['E']
(4, 0)
>>> font['R']
(2, 1)
>>> font['G']
(1, 1)
>>> font['O']
(0, 1)

>>> count_straight_lines('ERGONOMICS', font)
17
>>> count_curved_lines('ERGONOMICS', font)
6

>>> straight_lines_only('dictionary.txt6', font)
{'ALKALINE', 'MILLENNIAL', 'INFINITELY'}
>>> curved_lines_only('dictionary.txt7', font)
{'COCCUS', 'COUSCOUS'}
>>> balanced_lines('dictionary.txt8', font)
{'AUGUSTUS', 'CROSSROAD', 'SUDOKU', 'COLUMBUS', 'PROCESSORS'}

Resources