def parse_cigar(cigar):
    """
    Parse a cigar string into a list of operations
    
    :param cigar: a cigar string
    :returns:     A list of tuples of the form (length, operation)
    """
    cigar = cigar
    ops = []
    while len(cigar) > 0:
        for i, c in enumerate(cigar):
            if c in ("=", "X", "D", "I"):
                op = cigar[:i+1]
                ops.append((int(op[:-1]), op[-1]))
                cigar = cigar[i+1:]
                break
    return ops