def match_genes(i, j):
    """Returns a list of lists containing the excess, disjoint and,
    matching genes, respectively, between organisms i and j.

    Inputs:
    i: First organism. type: Genome
    j: Second organism. type: Genome
    """
    rtrn = []
    excess = []
    disjoint = []
    matching = []

    max_innov = max(i.innovation_range(), j.innovation_range())
    for k in range(1, max_innov + 1):
        if k > j.innovation_range() or k > i.innovation_range():
            excess.append(k)
        elif k not in j.connection_genes or k not in i.connection_genes:
            disjoint.append(k)
        else:
            matching.append(k)
    rtrn.append(excess)
    rtrn.append(disjoint)
    rtrn.append(matching)
    return rtrn