A teacher has taken exam of his students. He has stored marks in a dictionary where keys are the student's name and values are student's marks. Now he wants to know the name of students obtained minimum and maximum marks from this dictionary. You need to write a python function F-m-M(X) which takes dictionary as input and returns the name of student pair having minimum and maximum marks in the class. If input dictionary is empty return "Invalid Input".
Ex: Input : { 'Amit': 21, 'Aniket':34, 'Rohit': 53 }, Output: ('Amit', 'Rohit' )
Input: { } , Output: Invalid Input
def f_m_M(dict):
if len(dict) != 0:
items = dict.items()
min_value = min(items, key=lambda stud: stud[1])
max_value = max(items, key=lambda stud: stud[1])
return min_value + max_value
else:
return "Invalid input"
my_dict = { 'Amit': 44, 'Aniket':34, 'Rohit': 53 }
print(f_m_M(my_dict))
Comments
Leave a comment