-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathrm_smallest.py
More file actions
28 lines (22 loc) · 764 Bytes
/
Copy pathrm_smallest.py
File metadata and controls
28 lines (22 loc) · 764 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# take in argument d
def rm_smallest(d):
# if the dictionary is empty, return the original dictionary
if not d:
return d
# find the minimum value in the dictionary
min_value = min(d.values())
# find the key(s) that correspond to the minimum value
min_keys = [k for k, v in d.items() if v == min_value]
# remove the key-value pair(s) from the dictionary
for k in min_keys:
d.pop(k)
# return the modified dictionary
return d
def test():
assert 'a' in rm_smallest({'a':1,'b':-10}).keys()
assert not 'b' in rm_smallest({'a':1,'b':-10}).keys()
assert not 'a' in rm_smallest({'a':1,'b':5,'c':3}).keys()
assert rm_smallest({}) == {}
print("Success!")
if __name__ == "__main__":
test()