Light Mode
Dark Mode
Shorter Set Error
Task

In a given set of integers, you need to remove minimum and maximum elements.

The second argument tells how many min and max elements should be removed.

def removeminmax(data: set, total:int) -> set:

try:

for i in range(total):
 data.remove(max(data))
        data.remove(min(data))
    return data
except:
    data

AssertionError: assert removeminmax({8, 9, 7}, 2) == set()

What is the problem? I'm returning an empty set!

Created: Jan. 25, 2022, 8:08 p.m.
Updated: Jan. 25, 2022, 8:21 p.m.
0
10
User avatar
patonfop