def getLoops(main_twist, conjugate_by):
    """
    Returns two (homotopy classes of) loops for a twist.

    Pass in a main_twist (integer) and conjugate_by (list of integers);
    the braid you should construct is:
        conjugate_by main_twist conjugate_by^{-1}
    This braid corresponds to an element [f] of the mapping class group
    MCG(D) of a punctured disk D. MCG(D) acts on the fundamental group
    of D (with some basepoint fixed below the punctures).

    The return value encodes the homotopy classes of [f](r_1) and [f](r_2)
    where r_1 and r_2 are loops enclosing the punctures corresponding to
    the two strings involved in main_twist.

    The return value is formatted as [loop1, loop2].
    Each loop is written as a list of gaps (in +/- 1 thru n+1) through
    which it passes. Gap i lies between punctures i and i+1.

    A positive sign indicates an approach from below.
    As an artifact of the format and the choice of basepoint,
    each loop will alternate signs and begin with a positive entry.

    There is some ambiguity about whether the action described above
    is a left action or right action. I have chosen to take it as a left
    action in this implementation, but as long as you can apply an
    appropriate automorphism of the braid group, it shouldn't matter.

    """
    paths = [[main_twist + 1, -main_twist], [main_twist + 2, -main_twist - 1]]
    for twist in reversed(conjugate_by):
        for i in range(len(paths)):
            a = []
            for x in paths[i]:
                if abs(x) == abs(twist) + 1:
                    if twist < 0:
                        a.extend([x + 1, -x, x - 1])
                    else:
                        a.extend([x - 1, -x, x + 1])
                else:
                    a.append(x)
            paths[i] = a
    return paths
