Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!ecngs!feeder2.ecngs.de!81.171.88.16.MISMATCH!hq-usenetpeers.eweka.nl!hq-usenetpeers.eweka.nl!bcyclone03.am1.xlned.com!bcyclone03.am1.xlned.com!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!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; 'operator': 0.03; 'subject:Python': 0.06; 'assign': 0.07; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'wrote': 0.14; 'added.': 0.16; 'itemgetter': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'import': 0.22; 'print': 0.22; 'header:X-Complaints-To:1': 0.27; 'related': 0.29; 'code': 0.31; 'keys': 0.31; 'subject:with': 0.35; 'but': 0.35; 'there': 0.35; 'ordered': 0.36; 'skip:j 20': 0.36; 'thanks': 0.36; 'to:addr :python-list': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'called': 0.40; 'here': 0.66; 'response.': 0.68; 'dict.': 0.84; 'ordered.': 0.84; 'received:myvzw.com': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Dave Angel Subject: Re: Parsing Python dictionary with multiple objects Date: Wed, 15 Oct 2014 13:43:58 -0400 (EDT) Organization: news.gmane.org References: <64f7e57a-4be3-44f4-b11c-0d270fc91809@googlegroups.com> <7582dd3f-c0e1-4d5e-a03e-20bf711d1e79@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: 109.sub-70-192-196.myvzw.com 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: 44 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1413394863 news.xs4all.nl 2949 [2001:888:2000:d::a6]:58512 X-Complaints-To: abuse@xs4all.nl X-Received-Body-CRC: 3825729429 X-Received-Bytes: 3732 Xref: csiph.com comp.lang.python:79162 Anurag Patibandla 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