def category_and_ancestors(category):
    """Generate a list of strings: a category and all its ancestors.

    >>> for c in category_and_ancestors('Expenses.Travel.PyCon'):
    ...     c
    ...
    'Expenses.Travel.PyCon'
    'Expenses.Travel'
    'Expenses'

    """
    i = category.rfind('.')
    while i != -1:
        yield category
        category = category[:i]
        i = category.rfind('.')
    yield category
