[Tutor] 3 Dimensional Dictionaries

Sunil Tech sunil.techspk at gmail.com
Sat Jul 20 12:17:02 CEST 2013


Hi Everyone,

I have a list of dictionaries like

world =
[{'continent':'Asia','continent_code':1,'ocean':'Pacific','country':'India','country_code':1,'state':'Kerala',
'state_pin':500001},
 {'continent':'Asia','continent_code':1,'ocean':'Pacific','country':'India','country_code':1,'state':'Karnataka',
'state_pin':500002},
 {'continent':'Africa','continent_code':2,'ocean':'Atlantic','country':'Egypt','country_code':2,'state':'East
Egypt', 'state_pin':700001},
 {'continent':'Africa','continent_code':2,'ocean':'Atlantic','country':'Egypt','country_code':2,'state':'West
Egypt', 'state_pin':700002},
 {'continent':'Africa','continent_code':2,'ocean':'Atlantic','country':'Egypt','country_code':2,'state':'North
Egypt', 'state_pin':700003}]


i am trying to to make it in this format

world = [{'continent':'Asia', 'ocean':'Pacific',
 'countries':[{'country':'India',
'states':[{'state':'Kerala', 'state_pin':500001},
 {'state':'Karnataka', 'state_pin':500002}]
}]
 },
{'continent':'Africa', 'ocean':'Atlantic',
 'countries':[{'country':'Egypt',
'states':[{'state':'East Egypt', 'state_pin':700001},
 {'state':'West Egypt', 'state_pin':700002},
{'state':'North Egypt', 'state_pin':700003}]
 }]
}
]


Please help me in this regard.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20130720/c9127d0d/attachment.html>


More information about the Tutor mailing list