| | |
Problem extracting values of a Dictionary
Thread Solved |
•
•
Join Date: Feb 2006
Posts: 6
Reputation:
Solved Threads: 0
Hi! Thanks for your help in advance.....
Heres my case
I have a dictionary "d" with keys as string and a dictionary as integer "1" as keys to a list [1,2,3]
Now when I try looping through it........it gives me an error
it just prints test.tif
for some reason it just takes the key as a list of strings
Any solution to go arounf this problem?
Thanks
Shaf
Heres my case
I have a dictionary "d" with keys as string and a dictionary as integer "1" as keys to a list [1,2,3]
Python Syntax (Toggle Plain Text)
d{"test.tif": {1: [1,2,3]}}
Python Syntax (Toggle Plain Text)
for i in d: for j in i: print j
it just prints test.tif
for some reason it just takes the key as a list of strings
Any solution to go arounf this problem?
Thanks
Shaf
•
•
Join Date: Sep 2005
Posts: 133
Reputation:
Solved Threads: 58
Hi!
So i is a string, and when you say for j in i: you iterate over that string
Maybe you want one of the following:
Regards, mawe
Python Syntax (Toggle Plain Text)
In [4]: for i in d: ...: print i ...: test.tif
Maybe you want one of the following: Python Syntax (Toggle Plain Text)
In [5]: for i in d: ...: for j in d[i]: ...: print j ...: 1 In [6]: for i in d: ...: for j in d[i]: ...: print d[i][j] ...: [1, 2, 3] In [8]: for i in d: ...: for j in d[i]: ...: for k in d[i][j]: ...: print k ...: 1 2 3
•
•
Join Date: Feb 2006
Posts: 6
Reputation:
Solved Threads: 0
thanks ....but I figured it out.....
this is what I did.......
now "m" has the inner list......
Thanks for the reply......but before on the second loop.....I did this
the third for loop threw me off........I didnt know that I have to do it j[i][l]
format........thanks a lot
this is what I did.......
Python Syntax (Toggle Plain Text)
for l in j: z = j[l] for r in z: m = z[r]
now "m" has the inner list......
Thanks for the reply......but before on the second loop.....I did this
Python Syntax (Toggle Plain Text)
for l in j: for r in j[l]: for m in j[l[r]]: print m
the third for loop threw me off........I didnt know that I have to do it j[i][l]
format........thanks a lot
There are also some dictionary functions that can give you access to the inner sanctum:
Python Syntax (Toggle Plain Text)
d = {"test.tif": {1: [1,2,3]}} for key, dic in d.iteritems(): for x in dic.values()[0]: print x """ result = 1 2 3 """
May 'the Google' be with you!
![]() |
Similar Threads
- Missing Folder Options problem but the regedit values is normal (Viruses, Spyware and other Nasties)
- Problem with Deviation function (Python)
- Problem in getting values of a text area by row and column wise (ASP)
- a problem wilth C program (C)
Other Threads in the Python Forum
- Previous Thread: Weird problem with float or double....
- Next Thread: Help
| Thread Tools | Search this Thread |
address alarm anydbm app beginner cipher conversion coordinates curves cx-freeze data development dictionary directory dynamic examples excel feet file float format function generator getvalue gui halp handling homework images import input ip itunes java keycontrol line linux list lists loan loop maintain maze millimeter mouse mysqldb number numbers output parsing path port prime programming projects py2exe pygame pyglet pymailer python queue random recursion recursive screensaverloopinactive script scrolledtext searchingfile shebang slicenotation split ssh string strings table terminal text thread threading time tlapse tooltip tuple tutorial type ubuntu unicode url urllib urllib2 variable variables ventrilo verify vigenere web webservice wx.wizard wxpython xlwt






