info_outline

Solutions will be available when this assignment is resolved, or after a few failing attempts.

Count Lines Starting with each Letter

Write a function that receives the path to a text file that contains JUST ONE word
per line, and returns a dictionary with the counter of words starting with each
letter from 'a' to 'z'.

Example:

counter_by_letter('words.txt')  
# {
'a': 2,
'b': 10,
'c': 0,
...
'z': 1
}

Test Cases

test first letter count - Run Test

import tempfile

def test_first_letter_count():
    fp = tempfile.NamedTemporaryFile(mode="w")
    fp.write('tree\n')
    fp.write('car\n')
    fp.write('car\n')
    fp.write('house\n')
    fp.flush()

    counter = counter_by_letter(fp.name)
    assert len(counter.keys()) == 26
    assert counter['c'] == 2
    assert counter['t'] == 1
    assert counter['h'] == 1
    assert counter['m'] == 0

    fp.close()
def counter_by_letter(filepath): pass