जब किसी शब्दकोश में विशिष्ट मानों से जुड़ी कुंजियों को खोजने की आवश्यकता होती है, तो 'इंडेक्स' पद्धति का उपयोग किया जा सकता है।
नीचे उसी का प्रदर्शन है -
उदाहरण
my_dict ={"Hi":100, "there":121, "Mark":189}
print("The dictionary is :")
print(my_dict)
dict_key = list(my_dict.keys())
print("The keys in the dictionary are :")
print(dict_key)
dict_val = list(my_dict.values())
print("The values in the dictionary are :")
print(dict_val)
my_position = dict_val.index(100)
print("The value at position 100 is : ")
print(dict_key[my_position])
my_position = dict_val.index(189)
print("The value at position 189 is")
print(dict_key[my_position]) आउटपुट
The dictionary is :
{'Hi': 100, 'there': 121, 'Mark': 189}
The keys in the dictionary are :
['Hi', 'there', 'Mark']
The values in the dictionary are :
[100, 121, 189]
The value at position 100 is :
Hi
The value at position 189 is
Mark स्पष्टीकरण
-
एक शब्दकोश परिभाषित किया गया है, और कंसोल पर प्रदर्शित होता है।
-
शब्दकोश की कुंजियों को '.keys' का उपयोग करके एक्सेस किया जाता है और एक सूची में परिवर्तित किया जाता है।
-
यह एक वैरिएबल को असाइन किया गया है
-
शब्दकोश के मूल्यों को '.values' का उपयोग करके एक्सेस किया जाता है और एक सूची में परिवर्तित किया जाता है।
-
यह किसी दूसरे वेरिएबल को असाइन किया गया है।
-
मान अनुक्रमणिका को एक चर के लिए एक्सेस और असाइन किया जाता है।
-
यह आउटपुट के रूप में प्रदर्शित होता है।