def ant2bl(i, j=None):
    """Returns baseline index for given antenna pair.  Will accept
    two args, or a list/tuple/etc.  Uses 0-based indexing"""
    if j is None:
        a1, a2 = sorted(i[:2])
    else:
        a1, a2 = sorted((i, j))
    return a2 * (a2 - 1) // 2 + a1
