How to remove element in list after replacing, in a loop for next largest in list

Write a function that replaces each integer with the next largest in the list.
Examples
replace_next_largest([5, 7, 3, 2, 8]) ➞ [7, 8, 5, 3, -1]
replace_next_largest([2, 3, 4, 5]) ➞ [3, 4, 5, -1]
replace_next_largest([1, 0, -1, 8, -72]) ➞ [8, 1, 0, -1, -1]

https://afteracademy.com/blog/find-the-next-greater-element-for-every-element-in-an-array

?? did not pop after replace next largest in list

def replaceNextLargest(numLst):

    result = []

    for i in range(len(numLst)):
        found = False
        for j in range(len(numLst)):
            if numLst[j] > numLst[i]:
                found = True
                result.append(numLst[j])
                break
        if found == False:
            result.append(-1)

    return result

print( replaceNextLargest( [5, 7, 3, 2, 8] ))
return [7, 8, 5, 5, -1]

Answer

try this bro just add a check if the element already exist or not i think it may works if it fails at condition please comment

def replaceNextLargest(numLst):

    result = []

    for i in range(len(numLst)):
        found = False
        for j in range(len(numLst)):
            print(numLst[j], numLst[i])
            if numLst[j] > numLst[i] and numLst[j] not in result :
                found = True
                result.append(numLst[j])
                break
        if found == False:
            result.append(-1)

return result

print( replaceNextLargest( [5, 7, 3, 2, 8] ))