#! /usr/bin/python3

class CountWords():
    """
    Use a dict comprehension to create a word repository.
    """
    repo = {}

    def __init__(self, alist):
        {self._insert(x) for x in alist}

    def _insert(self, word):
        key = len(word)
        if key not in self.repo:
            self.repo[key] = []
        self.repo[key].append(word)

def test_dictionary_comprehension():
    alist = ['twas', 'brillig', 'and', 'the', 'slithy', 'toves', 'did']
    test_data = CountWords(alist)
    assert len(test_data.repo.keys()) == 5
    assert len(test_data.repo[3]) == 3

    even_dict = {k:test_data.repo[k] for k in test_data.repo.keys() if k % 2 == 0}
    assert len(even_dict) == 2