def compare_factors(list1, list2):

    length_1 = len(list1)
    length_2 = len(list2)

    list_1_factors = []
    list_2_factors = []

    overlap = [] # A map of where the first number of the pair matches betweent the two lists

    final_value = 0 # Number of common numbers

    for x in range(length_1): # Puts the first number in each tuple in a list
        list_1_factors.append(list1[x][0])
        x += 1

    for x in range(length_2): # Puts the second number in each tuple in a list
        list_2_factors.append(list2[x][0])
        x += 1

    for x in range(len(list_1_factors)): # If the first number in each tuple is the same in both lists, right true
        if list_1_factors[x] == list_2_factors[x]:
            overlap.append(True)
        else:
            overlap.append(False)

    for index in range(len(overlap)): # Finds how many times there is a common number between the lists
        if overlap[index]:
            if list1[index][1] < list2[index][1]:
                final_value += list1[index][2]
            else:
                final_value += list2[index][1]

    total_nums = 0
    for pair in list1: # Finds the total number of numbers
        total_nums += pair[1]
    for pair in list2:
        total_nums += pair[1]

    output = float(final_value)/float(total_nums) # Divides the number of common numbers by the total number of numbers

    return output