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


Groups > comp.lang.python > #79117

Re: Parsing Python dictionary with multiple objects

Newsgroups comp.lang.python
Date 2014-10-14 14:15 -0700
References <64f7e57a-4be3-44f4-b11c-0d270fc91809@googlegroups.com> <mailman.14856.1413305953.18130.python-list@python.org>
Message-ID <b3d199b6-c9ed-4efb-acf2-93f16b5dd8d3@googlegroups.com> (permalink)
Subject Re: Parsing Python dictionary with multiple objects
From Anurag Patibandla <anuragpatibandla7@gmail.com>

Show all headers | View raw


On Tuesday, October 14, 2014 12:59:27 PM UTC-4, Dave Angel wrote:
> anuragpatibandla7@gmail.com Wrote in message:
> 
> > I have a dictionary that looks like this:
> 
> > {"1":{"Key1":"Value1", "Key2":"Value2", "Key3":"Value3"}, 
> 
> > "2":{"Key1":"Value1", "Key2":"Value2", "Key3":"Value3"}, 
> 
> > "3":{"Key1":"Value1", "Key2":"Value2", "Key3":"Value3"}, 
> 
> > "4":{"Key1":"Value1", "Key2":"Value2", "Key3":"Value3"}}
> 
> > 
> 
> > Now if I have 100 objects like these and I need to split them into 3 smaller dicts in a ratio 2:3:5, how could I do that?
> 
> 
> 
> I really have no idea what that means.  You have 100 dicts of
> 
>  dicts? Are the keys unique? If so, you could combine them with a
> 
>  loop of update.
> 
> 
> 
> > I tried using numpy.random.choice(), but it says it needs to be a 1-d array.
> 
> > 
> 
> 
> 
> How about random.choice?  It needs a sequence.
> 
> 
> 
> To get anything more concrete, you need to specify Python version,
> 
>   and make a clearer problem statement,  perhaps with example of
> 
>  what you expect.
> 
> 
> 
> 
> 
> -- 
> 
> DaveA

Hey DaveA,
I am using Python 2.7.
Yes. I have a dict of dicts with keys ranging from 1..100
And the value of each of these keys is another dict. What I need to do is make 3 smaller dicts and assign the values of keys 1..100 in the ratio 2:3:5.
For example, if my original dict is 

d={"1":{"Key1":"Value1", "Key2":"Value2", "Key3":"Value3"}, 
   "2":{"Key1":"Value1", "Key2":"Value2", "Key3":"Value3"}, 
   "3":{"Key1":"Value1", "Key2":"Value2", "Key3":"Value3"}, 
   "4":{"Key1":"Value1", "Key2":"Value2", "Key3":"Value3"}}
   ...
   ...
  "100":{"Key1":"Value1", "Key2":"Value2", "Key3":"Value3"}

I need to have three dicts d1, d2, d3 with d1 containing the values of first 20 keys, d2 containing the values on next 30 keys and d3 containing the values of the next 50.
Can you please help me with this?

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