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


Groups > comp.lang.python > #79163

Re: Parsing Python dictionary with multiple objects

From Dave Angel <davea@davea.name>
Subject Re: Parsing Python dictionary with multiple objects
Date 2014-10-15 13:50 -0400
Organization news.gmane.org
References <64f7e57a-4be3-44f4-b11c-0d270fc91809@googlegroups.com> <ffa7f241-f01a-4a56-b94c-b2dd07b50270@googlegroups.com> <7056aefb-600a-4bcf-a4f2-2b0f45824c88@googlegroups.com> <5f3989af-31bf-4896-9770-a7703b8b9a58@googlegroups.com>
Newsgroups comp.lang.python
Message-ID <mailman.14885.1413395274.18130.python-list@python.org> (permalink)

Show all headers | View raw


Anurag Patibandla <anuragpatibandla7@gmail.com> 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

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