You could find several url's to scrape the data from, and I believe it was mentioned you could use a list of dicts, but it seems that you might want to sub tier your dicts, It's been a while since I've pythoned so this a little longer that usual, but this may help if you pull in the countries/continents/states/provinces/zipcodes, however you may stil want to give a DB a try, which you can create on your own out of dictionaries/with list tuples, and subdicts.
\but if you always wnat dynamic data, rescraping several url's at a personally optimized frequency into your db could help import random continents = ['china','u.s'] def world_stats(): world = {} for continent in continents: world[continent] = {'periodic_table_resources': {} } print(continent) for periodic_elements in range(0,119): rand = random.randint(0,101) world[continent]['periodic_table_resources'] = 'periodic_table_element %i=' % (periodic_elements) print(world[continent]['periodic_table_resources'], rand, '%') world_stats() This doesn't contain the url scraper yet. On Mon, Jul 22, 2013 at 10:44 PM, Sunil Tech <sunil.tech...@gmail.com>wrote: > > > On Tuesday, July 23, 2013, Sunil Tech <sunil.tech...@gmail.com> wrote: > > 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 > > -- Best Regards, David Hutto *CEO:* *http://www.hitwebdevelopment.com*
_______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor