Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Not a one-liner. Commented. solution in Clear category for Shorter Set by Selindian
def remove_min_max(data: set, total:int) -> set:
# your code here
if total * 2 >= len(data): return set() # If we should remove all / more than set includes: Return empty set
mylist = list(data) # Sets are immutable. Convert it to list to be able to remove things.
while total > 0: # We need a loop as we need to remove min/max x-times. Ends when total reaches 0.
mylist.remove(min(mylist)) # Remove min
mylist.remove(max(mylist)) # Remove max
total -= 1 # Reduce total by 1
return set(mylist) # Convert list to set and return it.
print('Example:')
print(remove_min_max({4,5,6,7}, 1))
assert remove_min_max({8, 9, 18, 7}, 1) == {8, 9}
assert remove_min_max({8, 9, 7}, 0) == {8, 9, 7}
assert remove_min_max({8, 9, 7}, 2) == set()
assert remove_min_max({1, 2, 7, 8, 9}, 2) == {7}
assert remove_min_max(set(), 1) == set()
print("The first mission is done! Click 'Check' to earn cool rewards!")
Feb. 22, 2022