0

Python_dict(plzzz explain it)

D = {1 : {'A' : {1 : "A"}, 2 : "B"}, 3 :"C", 'B' : "D", "D": 'E'} print(D[D[D[1][2]]], end = " ") print(D[D[1]["A"][2]])

7th May 2020, 10:42 AM
Siddhant Saxena
Siddhant Saxena - avatar
2 Answers
+ 1
Second one is wrong tho,there is no key with D[1]["A"][2] At key 1 there is 1:{"A":{1:"A"},2:"B"} Inside it at key "A" there is "A":{1:"A"} But there is no key inside it with 2
7th May 2020, 10:58 AM
Abhay
Abhay - avatar
+ 5
Ok first you should understand that end="" has no work here it basically used in range . Now let us start from beginning. You had declared a dictionary which contain dictionary itself . So here . D[1][2] will first search for 1 key in dictionary now the value for key 1 is {'A':{1:"A"},2:"B"} ok now it will search for key 2 and the value for key 2 is B now your code will be simplified to D[D["B"]] Now procedue further D["B"] will result in D and then it will be simplified to D["D"] so it will result in E because D Is keyword of value E . Similarly do second one for your self
7th May 2020, 10:54 AM
Ayush Kumar
Ayush Kumar - avatar