How to declare a multi dimensional dictionary in Python?

PythonServer Side ProgrammingProgramming

Let us declare three dictionary objects as below −

>>> d1={"name":"Ravi","age":25, "marks":60}
>>> d2={"name":"Anil","age":23, "marks":75}
>>> d3={"name":"Asha", "age":20, "marks":70}

Now we shall use them as values in a parent dictionary

{1: {'name': 'Ravi', 'age': 25, 'marks': 60}, 2: {'name': 'Anil', 'age': 23, 'marks': 75}, 3: {'name': 'Asha', 'age': 20, 'marks': 70}}

Here d1, d2 and d3 are assigned as value to keys 1,2,3

twodimdict [1] returns d1. Value of a key inside d1 can be obtained as below −

{'name': 'Ravi', 'age': 25, 'marks': 60}

Note that the dictionary items are not indexed.

Updated on 25-Feb-2020 12:17:38