Nov-22-2020, 04:08 PM
You want to use remove(), which has the problem of removing the first instance. The following removes that largest element until there are no longer any matching elements
a = [4,6,8,10,4,7,10,9] c = max(a) try : while True: a.remove(c) except ValueError: pass print(a)
Output:[4, 6, 8, 4, 7, 9]