Rules:
You may NOT use the following built-in functions.
sort()
sum()
max()
min()
Except for format()
all string methods are banned. Except for append() and extend()
all list methods are banned. You may not import any module.
Make sure to test your code with a variety of inputs. Do not assume the examples in these directions are reflective of the hidden test cases.
part 5 Key to Min
Write a function called get_key_to_min that takes a dictionary and returns the key of the smallest value in the dictionary that is greater than or equal to 10.
About the values in the given dictionary, you may assume:
1.They are all integers that do not exceed 1000.
2.They are all unique (i.e. different from each other).
Here are some examples of how your program should behave on Python IDLE.
>>> get_key_to_min({'a':5,'b':8,'abc':13,'def':18,'xyz':10})
'xyz'
>>> get_key_to_min({'a':5,'b':8,'abc':13,'def':18,'xyz':9})
'abc'
>>> get_key_to_min({'a':12,'b':8,'abc':13,'def':18,'xyz':9})
'a'
Given below is the code for the function. I have also give the
code to test the function.
PLEASE MAKE SURE INDENTATION IS EXACTLY AS SHOWN IN IMAGE.
Please do rate the answer if it helped. Thank you.
def get_key_to_min(dic):
min_val = None
key_to_min = None
for k in dic:
if dic[k] >= 10 and (min_val ==
None or dic[k] < min_val):
min_val =
dic[k]
key_to_min =
k
return key_to_min
#testing the function
print(
get_key_to_min({'a':5,'b':8,'abc':13,'def':18,'xyz':10}))
print(get_key_to_min({'a':5,'b':8,'abc':13,'def':18,'xyz':9}))
print(
get_key_to_min({'a':12,'b':8,'abc':13,'def':18,'xyz':9}))

output
---
xyz
abc
a
Rules: You may NOT use the following built-in functions. sort() sum() max() min() Except for format()...