Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!news.stack.nl!newsfeed.xs4all.nl!newsfeed1.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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'subject:Python': 0.06; 'attribute': 0.07; 'error:': 0.07; 'wednesday,': 0.07; 'expected.': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'wrote': 0.14; 'dictionary.': 0.16; 'key?': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'wrote:': 0.18; 'print': 0.22; '15,': 0.26; 'header:X-Complaints-To:1': 0.27; 'gives': 0.31; "skip:' 10": 0.31; 'that.': 0.31; 'keyerror:': 0.31; 'keys': 0.31; 'lists': 0.32; 'subject:with': 0.35; 'but': 0.35; 'there': 0.35; 'skip:j 20': 0.36; 'to:addr:python-list': 0.38; 'expect': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'entire': 0.61; '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:50:54 -0400 (EDT) Organization: news.gmane.org References: <64f7e57a-4be3-44f4-b11c-0d270fc91809@googlegroups.com> <7056aefb-600a-4bcf-a4f2-2b0f45824c88@googlegroups.com> <5f3989af-31bf-4896-9770-a7703b8b9a58@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: 60 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1413395274 news.xs4all.nl 2936 [2001:888:2000:d::a6]:35260 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:79163 Anurag Patibandla Wrote in message: > On Wednesday, October 15, 2014 1:10:41 PM UTC-4, Rustom Mody wrote: >> On Wednesday, October 15, 2014 10:30:49 PM UTC+5:30, Anurag Patibandla wrote: >> >> > 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 >> >> > for i in b: >> >> > queues = order[n:n+i] >> >> >> >> > n = n+i >> >> > lists = [(queues[j], json.get(queues[j])) for j in range(len(queues))] >> >> >> >> > dicts = dict(lists) >> >> > print dicts >> >> > print dict[0] >> >> >> >> >> >> > print dicts works as expected. It gives me the entire dictionary. But when I do dicts[0], there is the following error: >> >> > 'type' object has no attribute '__getitem__' >> >> >> >> Do you want dict[0] ?? >> >> I think you want dicts[0] > > Sorry about that. > dicts[0] gives me a KeyError: 0 > If the keys are all strings, why would you expect to find any items with an int key? -- DaveA