I am new to python started few days back. Can anyone help me achieve following objective?
I have two lists -
mylist1 = ["Country", "State", "City", "Name", "Age"]
The another list -
mylist2 = [["India", "Maharashtra", "Mumbai", "Tom", 30],
["India", "Maharashtra", "Mumbai", "John", 40],
["India", "Maharashtra", "Pune", "Ronny", 25]
["India", "Madhya Pradesh", "Indore", "Jade", 35]]
The user will the level of dictionary e.g.
level = 4
So dictionary of depth 3 should be created as given below -
mydict = {"India":{"Maharashtra":{"Mumbai":{"Tom":{"Age":30},"John":{"Age":40}},
"Pune" :{"Ronny":{"Age":25}},
"Madhya Pradesh":{"Indore": {"Jade": {"Age" : 35}}}
}
There could be some typos in above dictionary. I haven't tried anything to get this working.
Also note that, the above lists can be changed as follow -
mylist1 = ["State", "City", "Name", "Age"]
The another list -
mylist2 = [["Maharashtra", "Mumbai", "Tom", 30],
["Maharashtra", "Mumbai", "John", 40],
["Maharashtra", "Pune", "Ronny", 25]
["Madhya Pradesh", "Indore", "Jade", 35]]
Hence user may provide level = 3 in above case.