Mid2 26th_Inverted_Dictionary_Creation
def inverted_dict(d):
d1={value:key for key,value in d.items()}
print(d1)
number=int(input("Enter the entries: "))
d={}
for i in range(number):
key=input("Enter the student name: ")
value=input("Enter the marks: ")
d[key]=int(value)
print(d)
print("inverted dictionary: ")
inverted_dict(d)
#ouput:
Enter the entries: 2
Enter the student name: ubed
Enter the marks: 23
Enter the student name: rounak
Enter the marks: 21
{'ubed': 23, 'rounak': 21}
inverted dictionary:
{23: 'ubed', 21: 'rounak'}
Comments
Post a Comment