Using get function in dictionary

Dear All,
The following is my dictionary.
my_dict = {1: ‘apple’, 2: ‘mango’,3:‘banana’,4:{1 :{‘A’ : ‘orange’, ‘B’ : ‘grape’},2:{‘C’:‘Melon’,‘D’:‘jackfruit’}}}
I can access the element “Melon” using
print(my_dict[4][2][‘C’])

How do i get the same using my_dict.get() method. As i read in the documentation get method can be used for one key only. Just wanted to understand from the experts.

Thanks in Advance.
Thanks & Regards
Saravanan Shanmugham

Hi @saravananshanmugham,
You can use the following snippet :

my_dict.get(4).get(2).get('C')
1 Like

Thanks a lot Ishvinder. It worked. Somehow the documentation is not clear.

1 Like