THANK YOU ALL for your time. The first format which I pasted was from the DB
The second format(exactly the same), is to be sent to the view. If the logic can be fitted in One or two methods it'll help me to easily understand & to apply. so I request you to help... On Sunday, July 21, 2013, Alan Gauld <alan.ga...@btinternet.com> wrote: > On 20/07/13 11:17, Sunil Tech wrote: >> >> 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}, > >> >> 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}] >> }] >> }, > >> Please help me in this regard. > > In what regard? Where do you need the help? > You seem to know the data format you want? > > The only thing I'd suggest is to consider using classes if you are familiar with them. > > world => list of continents > continent => class containing countries > country => class containing states > state => class containing data > > It then becomes easier to build helper methods to extract/manipulate the data you are interested in. > > Alternatively, if you have a large amount of data a database may be another option. Swap table for class above and use SQL to manage the data. > > But other than those suggestions I don't know what kind of > help you want? > > -- > Alan G > Author of the Learn to Program web site > http://www.alan-g.me.uk/ > > _______________________________________________ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor >
_______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor