Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #79167

Re: Parsing Python dictionary with multiple objects

Newsgroups comp.lang.python
Date 2014-10-15 11:35 -0700
References <64f7e57a-4be3-44f4-b11c-0d270fc91809@googlegroups.com> <7582dd3f-c0e1-4d5e-a03e-20bf711d1e79@googlegroups.com> <mailman.14884.1413394863.18130.python-list@python.org>
Message-ID <7779f647-b676-47b6-82b4-d3024299cf7c@googlegroups.com> (permalink)
Subject Re: Parsing Python dictionary with multiple objects
From Anurag Patibandla <anuragpatibandla7@gmail.com>

Show all headers | View raw


On Wednesday, October 15, 2014 1:41:13 PM UTC-4, Dave Angel wrote:
> Anurag Patibandla <anuragpatibandla7@gmail.com> Wrote in message:
> 
> > Thanks for the response.
> 
> > Here is the code that I have tried.
> 
> > 
> 
> > from operator import itemgetter
> 
> > keys = json.keys()
> 
> > order = list(keys)
> 
> > q1 = int(round(len(keys)*0.2))
> 
> > q2 = int(round(len(keys)*0.3))
> 
> > q3 = int(round(len(keys)*0.5))
> 
> > b = [q1,q2,q3]
> 
> > n=0
> 
> 
> 
> threedicts = []
> 
> 
> 
> > for i in b:
> 
> >     queues = order[n:n+i]
> 
> >         
> 
> >     n = n+i
> 
> >     print queues
> 
> >     
> 
> >     for j in range(len(queues)):
> 
> >         q = (queues[j], json.get(queues[j]))
> 
> >         print q
> 
> > 
> 
> 
> 
>        onedict = {}
> 
>        for q in queues:
> 
>            onedict[q] = json[q]
> 
>        threedicts.append (onedict)
> 
>    dict1, dictw, dict3 = threedicts 
> 
>            
> 
> > By this I am able to get the 3 smaller dicts I want, but can you help me assign them to 3 variables?
> 
> > The dicts need not be ordered but it would be better if they are ordered.
> 
> > 
> 
> 
> 
> dicts are not ordered. If you want the items in a particular
> 
>  order, you have to do that after extraction from the dict. There
> 
>  is a related type called collections.OrderedDict, which
> 
>  'remembers' the order things were added.
> 
> 
> 
> -- 
> 
> DaveA

Thanks DaveA!
This works perfectly!

Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Parsing Python dictionary with multiple objects anuragpatibandla7@gmail.com - 2014-10-14 08:57 -0700
  Re:Parsing Python dictionary with multiple objects Dave Angel <davea@davea.name> - 2014-10-14 13:02 -0400
    Re: Parsing Python dictionary with multiple objects Anurag Patibandla <anuragpatibandla7@gmail.com> - 2014-10-14 14:15 -0700
      Re: Parsing Python dictionary with multiple objects Skip Montanaro <skip.montanaro@gmail.com> - 2014-10-14 16:32 -0500
        Re: Parsing Python dictionary with multiple objects Anurag Patibandla <anuragpatibandla7@gmail.com> - 2014-10-14 14:36 -0700
      Re: Parsing Python dictionary with multiple objects MRAB <python@mrabarnett.plus.com> - 2014-10-14 23:58 +0100
  Re:Parsing Python dictionary with multiple objects Dave Angel <davea@davea.name> - 2014-10-14 21:57 -0400
    Re: Parsing Python dictionary with multiple objects Rustom Mody <rustompmody@gmail.com> - 2014-10-14 19:32 -0700
  Re: Parsing Python dictionary with multiple objects Anurag Patibandla <anuragpatibandla7@gmail.com> - 2014-10-14 20:40 -0700
    Re: Parsing Python dictionary with multiple objects Rustom Mody <rustompmody@gmail.com> - 2014-10-14 21:50 -0700
    Re: Parsing Python dictionary with multiple objects Dave Angel <davea@davea.name> - 2014-10-15 13:43 -0400
      Re: Parsing Python dictionary with multiple objects Anurag Patibandla <anuragpatibandla7@gmail.com> - 2014-10-15 11:35 -0700
  Re: Parsing Python dictionary with multiple objects Anurag Patibandla <anuragpatibandla7@gmail.com> - 2014-10-14 20:41 -0700
  Re: Parsing Python dictionary with multiple objects Anurag Patibandla <anuragpatibandla7@gmail.com> - 2014-10-15 08:52 -0700
    Re: Parsing Python dictionary with multiple objects Rustom Mody <rustompmody@gmail.com> - 2014-10-15 09:06 -0700
  Re: Parsing Python dictionary with multiple objects Anurag Patibandla <anuragpatibandla7@gmail.com> - 2014-10-15 09:28 -0700
    Re: Parsing Python dictionary with multiple objects Rustom Mody <rustompmody@gmail.com> - 2014-10-15 09:43 -0700
      Re: Parsing Python dictionary with multiple objects Rustom Mody <rustompmody@gmail.com> - 2014-10-15 09:59 -0700
  Re: Parsing Python dictionary with multiple objects Anurag Patibandla <anuragpatibandla7@gmail.com> - 2014-10-15 09:57 -0700
    Re: Parsing Python dictionary with multiple objects Dave Angel <davea@davea.name> - 2014-10-15 13:48 -0400
  Re: Parsing Python dictionary with multiple objects Anurag Patibandla <anuragpatibandla7@gmail.com> - 2014-10-15 10:00 -0700
    Re: Parsing Python dictionary with multiple objects Rustom Mody <rustompmody@gmail.com> - 2014-10-15 10:10 -0700
      Re: Parsing Python dictionary with multiple objects Anurag Patibandla <anuragpatibandla7@gmail.com> - 2014-10-15 10:20 -0700
        Re: Parsing Python dictionary with multiple objects Dave Angel <davea@davea.name> - 2014-10-15 13:50 -0400
  Re: Parsing Python dictionary with multiple objects Anurag Patibandla <anuragpatibandla7@gmail.com> - 2014-10-15 10:20 -0700
    Re: Parsing Python dictionary with multiple objects Rustom Mody <rustompmody@gmail.com> - 2014-10-15 10:35 -0700
      Re: Parsing Python dictionary with multiple objects Anurag Patibandla <anuragpatibandla7@gmail.com> - 2014-10-15 11:27 -0700
        Re: Parsing Python dictionary with multiple objects Dave Angel <davea@davea.name> - 2014-10-15 18:25 -0400

csiph-web