def _pretty_name_list(names):
    """
    Given a list of (a,b) pairs, output aligned columns with the
    items of the second column parenthised.

    Used for pretty-printing e.g. name (crsid) or socname (socid) lists.
    """
    # might be given an iterator, need a list, might as well sort it
    nameList = sorted(names)
    try:
        maxlen = max(len(col1) for (col1, col2) in nameList)
    except ValueError:  # empty sequence
        return ''

    return ['  %-*s  (%s)' % (maxlen, col1, col2)
            for (col1, col2) in nameList]