import re


def helper(filename):
    """
    Reads file and build dictionary with words and their quantities in k,v
    :param filename: the file to be read
    :return: a dict with word: quantity
    """

    # get words from file (split by space)
    words = [w for line in open(filename).readlines() for w in line.split()]

    # remove pontuation and transform lowercase
    for i in range(len(words)):
        words[i] = re.sub(
            r'(`|_|\+|-|\.|,|\?|\!|@|#|\$|%|\^|&|\*|\(|\)|;|\\|\/|\||<|>|\"|\')',
            '', words[i])
        words[i] = words[i].lower()

    # cast to set to remove repeated words and sort by alphabetical order
    words_set = set(words)

    # build dictionary with word => quantity
    words_dict = dict()
    for w in words_set:
        words_dict[w] = words.count(w)

    # finally return the dict
    return words_dict