Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed4a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.007 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'that?': 0.05; 'subject:Python': 0.06; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'python': 0.11; 'wrote': 0.14; 'array.': 0.16; 'means.': 0.16; 'received:80.91.229.3': 0.16; 'received:97': 0.16; 'received:plane.gmane.org': 0.16; 'sequence.': 0.16; 'split': 0.19; 'example': 0.22; 'skip:{ 20': 0.24; 'specify': 0.24; 'looks': 0.24; 'this:': 0.26; 'skip:" 20': 0.27; 'header:X -Complaints-To:1': 0.27; 'tried': 0.27; 'idea': 0.28; 'keys': 0.31; 'update.': 0.31; 'says': 0.33; 'could': 0.34; 'problem': 0.35; 'subject:with': 0.35; 'objects': 0.35; 'but': 0.35; 'really': 0.36; 'so,': 0.37; 'version,': 0.38; 'to:addr:python- list': 0.38; 'anything': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'how': 0.40; 'email addr:gmail.com': 0.63; 'more': 0.64; 'statement,': 0.68; '100': 0.79; 'clearer': 0.84; 'subject::': 0.85; 'ratio': 0.91 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Dave Angel Subject: Re:Parsing Python dictionary with multiple objects Date: Tue, 14 Oct 2014 13:02:12 -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: 7bit 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 26 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1413305953 news.xs4all.nl 2927 [2001:888:2000:d::a6]:33336 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:79108 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