जब मिलान मूल्यों वाले शब्दकोशों को हटाना आवश्यक होता है, तो एक शब्दकोश समझ का उपयोग किया जाता है।
नीचे उसी का एक प्रदर्शन है -
उदाहरण
my_dict_1 = [{'Hi': 32, "there": 32, "Will":19},{'Hi': 19, "there": 100, "Will": 13}, {'Hi': 72, "there": 19, "Will": 72}]
print("The first dictionary is : ")
print(my_dict_1)
my_dict_2 = [{'Hi': 72, "Will": 19}, {"Will": 13, "Hi": 19}]
print("The second dictionary is : ")
print(my_dict_2)
K = "Hi"
print("The value of K is ")
print(K)
temp = { element[K] for element in my_dict_2}
my_result = [element for element in my_dict_1 if element[K] not in temp]
print("The result is : " )
print(my_result) आउटपुट
The first dictionary is :
[{'Hi': 32, 'there': 32, 'Will': 19}, {'Hi': 19, 'there': 100, 'Will': 13}, {'Hi': 72, 'there': 19, 'Will': 72}]
The second dictionary is :
[{'Hi': 72, 'Will': 19}, {'Will': 13, 'Hi': 19}]
The value of K is
Hi
The result is :
[{'Hi': 32, 'there': 32, 'Will': 19}] स्पष्टीकरण
-
दो शब्दकोश परिभाषित हैं और कंसोल पर प्रदर्शित होते हैं।
-
K के लिए एक मान परिभाषित किया गया है और कंसोल पर प्रदर्शित किया गया है।
-
दूसरे शब्दकोश को फिर से चालू किया जाता है, और तत्वों को K से जांचा जाता है और एक अस्थायी चर 'temp' में संग्रहीत किया जाता है।
-
पहले शब्दकोश को फिर से चालू किया जाता है, और इसमें तत्वों को अस्थायी चर 'अस्थायी' के साथ चेक किया जाता है और एक चर को सौंपा जाता है।
-
यह परिणाम एक चर को सौंपा गया है।
-
यह वह आउटपुट है जो कंसोल पर प्रदर्शित होता है।