def generatetfmatrix(matrix, idf):
    """
    Generate a new term weight matrix when supplied with the current `matrix` and
    the weighing factors `idf`. Returns a new matrix using lists.
    """
    docamount = len(matrix[0])  # get the amount of documents
    wordcount = len(matrix)
    updatedmatrix = list()  # create a new empty matrix
    updatedmatrix.append(matrix[0])  # set the header in the new matrix
    for i in range(1, wordcount):  
        # do the loop for all documents, excluding the term itself
        newrow = list()  # create a new row for the matrix
        currentrow = matrix[i]  # get the current row from the old matrix
        # from this current row, get the current word
        currentword = currentrow[0]
        # from the idf dictionary, get the value corresp. with the current term
        wordweight = idf.get(currentword)
        newrow.append(currentword)  # add the current term to the new row
        for y in range(1, docamount):
            # get the current value of the term we are calculating
            currentvalue = currentrow[y]
            # calculate the new value with the weighing applied
            updatedvalue = currentvalue * wordweight
            newrow.append(updatedvalue)  # save this new value in the new row
        # append the filled row to the updated matrix
        updatedmatrix.append(newrow)
    return updatedmatrix