def groupnames(name_iterable):
    """Return a dict keyed by last name initial with a value of a tuple of the
    names sorted by last first name.

    The items returned by name_iterable are expected to be strings containing
    the names formatted as ``first middle last`` with middle being optional.

    >>> groupnames(('Anna Martelli', 'Alex Martelli', 'Todd Cannon', 'Gwen C',
    ... 'John Doe'))
    {'C': ('Gwen C', 'Todd Cannon'), 'M': ('Alex Martelli', 'Anna Martelli'), 'D': ('John Doe',)}

    """
    sorted_names = sorted(name_iterable, key=sortkeyfunc)
    name_dict = {}
    for key, group in itertools.groupby(sorted_names, groupkeyfunc):
        name_dict[key] = tuple(group)
    return name_dict
Return a dict keyed by last name initial with a value of a tuple of the
    names sorted by last first name.

    The items returned by name_iterable are expected to be strings containing
    the names formatted as ``first middle last`` with middle being optional.

    >>> groupnames(('Anna Martelli', 'Alex Martelli', 'Todd Cannon', 'Gwen C',
    ... 'John Doe'))
    {'C': ('Gwen C', 'Todd Cannon'), 'M': ('Alex Martelli', 'Anna Martelli'), 'D': ('John Doe',)}

    
recipes/Python/303177_Sort_names_separate_last_name/recipe-303177.py