In: Computer Science
In Python:
Key1, value1
Key2, value2
…, …
(Please if you can, provide screenshots)
Thank YOU!
I put the code in python as your requirements. please go through code, also putting the screenshot of output of the code and if you have any doubt, feel free to comment down and if you like, please give me upvote.
mydict = {
"fruit1": "Banana",
"fruit2": "Apple",
"Car1": "BMW",
"Car2": "OD",
"Car3": "Toyota",
"Vegetable1": "Tomato"
}
# Adding a new key with value
mydict["Added_Vegetable"] = "Potato_added"
# Reassignment of one key
mydict["fruit1"] = "Banana_Updated"
# deleting Key Car2, so it will not be there in final list
del mydict["Car2"]
# Inclusion of Key:
print("\nInclusion: \n")
print("'fruit1' key is there or not ?")
print('fruit1' in mydict)
print("'fruit9' key is there or not ?")
print('fruit9' in mydict)
print("'Added_Vegetable' key is there or not ?")
print('Added_Vegetable' in mydict)
print("\nValue from key: ")
# Find value on key
print(mydict["fruit1"])
print(mydict["Car1"])
print(mydict["Added_Vegetable"])
# key list
key_list = list(mydict.keys())
# Value list
val_list = list(mydict.values())
print('\nKey from Values: ')
print(key_list[val_list.index("Apple")])
print(key_list[val_list.index("Toyota")])
print(key_list[val_list.index("Banana_Updated")])
print("\nDictionary: ")
for key in mydict:
print(key, mydict[key])