""" width.py """

# usage: python3 width.py [textfile] or reads from standard input

import sys


def lines(filename=None):
    """ yield the next line from filename or standard input """
    if filename is None:
        yield from sys.stdin
    else:
        with open(filename, 'r', encoding='utf-8') as fileobject:
            yield from fileobject


def width(filename=None):
    """ width summary of filename """
    store = {}
    for line in lines(filename):
        key = len(line.rstrip())
        value = store.get(key, 0)
        store[key] = value + 1

    output = [f'{key:3}: {store[key]}' for key in sorted(store.keys())]

    return '\n'.join(output)


if __name__ == '__main__':
    if len(sys.argv) == 1:
        print(width(None))
    else:
        print(width(sys.argv[1]))
