def sort_pipes(pipes, doc):
    """Sort pipes by theri systems name."""
    sorted_pipes = {}
    for pipe in pipes:
        system = pipe.MEPSystem
        system_type = doc.GetElement(system.GetTypeId())
        system_abbreviation = system_type.Abbreviation
        try:  # to add a pipe to a list
            sorted_pipes[system_abbreviation].append(pipe)
        except KeyError:  # create the list if it soes not exist yet
            sorted_pipes[system_abbreviation] = [pipe, ]
    return sorted_pipes