def _PartitionComps(er, comp, excepti, compa, compb):
    """Partition the edges of er by component number, into two lists.

    Generally, put odd components into first list and even into second,
    except that component compa goes in the first and compb goes in the second,
    and we ignore edge er[excepti].

    Args:
      er: list of (weight, el, tl, tr) (see _ERGraph)
      comp: dict - mapping triangle triple -> connected component index
      excepti: int - index in er to ignore (unless excepti==-1)
      compa: int - component to go in first list of answer (unless 0)
      compb: int - component to go in second list of answer (unless 0)
    Returns:
      (list, list) - a partition of er according to above rules
    """
    parta = []
    partb = []
    for i in range(0, len(er)):
        if i == excepti:
            continue
        tl = er[i][2]
        c = comp[tl]
        if c == compa or c != compb and c & 1 == 1:
            parta.append(er[i])
        else:
            partb.append(er[i])
    return parta, partb
