Parsing Python dictionary with multiple objects
Dave Angel
davea at davea.name
Wed Oct 15 13:50:54 EDT 2014
Anurag Patibandla <anuragpatibandla7 at 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
More information about the Python-list
mailing list