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


Groups > comp.lang.python > #79124

Re:Parsing Python dictionary with multiple objects

Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'that?': 0.05; 'subject:Python': 0.06; 'exception,': 0.09; 'imply': 0.09; 'keys,': 0.09; 'lines.': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'sub': 0.09; 'wrote': 0.14; 'thread': 0.14; 'array.': 0.16; 'conflicting': 0.16; 'dictionaries': 0.16; 'keys.': 0.16; 'received:80.91.229.3': 0.16; 'received:97': 0.16; 'received:plane.gmane.org': 0.16; 'sliced': 0.16; 'code.': 0.18; 'do.': 0.18; 'first.': 0.19; 'split': 0.19; 'skip:{ 20': 0.24; "haven't": 0.24; 'looks': 0.24; 'shown': 0.26; 'this:': 0.26; 'skip:" 20': 0.27; 'header:X-Complaints-To:1': 0.27; 'tried': 0.27; 'that.': 0.31; '20%': 0.31; 'says': 0.33; 'actual': 0.34; 'could': 0.34; 'subject:with': 0.35; 'objects': 0.35; 'but': 0.35; 'there': 0.35; 'method': 0.36; 'should': 0.36; 'two': 0.37; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'how': 0.40; "you'll": 0.62; "you've": 0.63; 'email addr:gmail.com': 0.63; 'show': 0.63; '30,': 0.65; '20,': 0.68; 'answer.': 0.68; '100': 0.79; 'goals': 0.81; 'subject::': 0.85; 'ratio': 0.91
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Dave Angel <davea@davea.name>
Subject Re:Parsing Python dictionary with multiple objects
Date Tue, 14 Oct 2014 21:57:08 -0400 (EDT)
Organization news.gmane.org
References <64f7e57a-4be3-44f4-b11c-0d270fc91809@googlegroups.com>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding 8bit
X-Gmane-NNTP-Posting-Host 97.73.240.9
X-Newsreader PiaoHong.Usenet.Client.VIP:1.62
X-Archive encrypt
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.14868.1413338052.18130.python-list@python.org> (permalink)
Lines 37
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1413338052 news.xs4all.nl 2881 [2001:888:2000:d::a6]:43267
X-Complaints-To abuse@xs4all.nl
Path csiph.com!usenet.pasdenom.info!bete-des-vosges.org!feed.ac-versailles.fr!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Xref csiph.com comp.lang.python:79124

Show key headers only | View raw


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 tried using numpy.random.choice(), but it says it needs to be a 1-d array.

> 

What have you actually tried? You haven't shown any actual code.

Look up the method dict.keys, and see how you might use that. Then
 look up random.shuffle, and see what it would do. Also look up
 dict.sort, since your two messages on this thread imply two
 conflicting goals as to which sub dictionaries should go in which
 of your buckets. 

As for extracting 20% of the keys, slicing is your answer. If
 there are 100 keys, 20, 30, and 50 need to be sliced
 off.

Then you'll need a loop to build each result dictionary from its keys.

There are shortcuts,  but it's best to learn the fundamentals first.

Try writing the code. If it doesn’t all work show us what you've
 tried, and what you think is wrong. And when you get an
 exception, show the whole traceback,  don't just paraphrase one
 of the lines.


-- 
DaveA

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