Python program to print the highest and lowest value in the dictionary

Here, we are going to write python program to print the highest and lowest value in the dictionary . We can dict() to create dictionary of items and insert number of items in dictionary using for loop. With the help of lambda function and inbuilt min and max function,we can find out maximum and minimum values of dictionary

Python program

items = dict()
n = int(input("Enter number of items :"))
for i in range(n):
        itemname = input("Enter names of item :")
        price= []
        cost = float(input("Enter cost :"))
        price.append(cost)
        items[itemname] = price
print("Dictionary of items created :")
print(items)
key_max = max(items.keys(), key=(lambda k: items[k]))
key_min = min(items.keys(), key=(lambda k: items[k]))
print('Maximum Value: ',items[key_max])
print('Minimum Value: ',items[key_min])



Output

Enter number of items :5
Enter names of item :snack
Enter cost :56
Enter names of item :mirinda
Enter cost :67
Enter names of item :cococola
Enter cost :88
Enter names of item :maggi
Enter cost :45
Enter names of item :cupcake
Enter cost :33
Dictionary of items created :
{'snack': [56.0], 'mirinda': [67.0], 'cococola': [88.0], 'maggi': [45.0], 'cupcake': [33.0]}
Maximum Value:  [88.0]
Minimum Value:  [33.0]
<