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]

d{"test.tif": {1: [1,2,3]}}

Now when I try looping through it........it gives me an error

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

Hi!

In [4]: for i in d:
   ...:     print i
   ...:
test.tif

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:

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

Regards, mawe

thanks ....but I figured it out.....

this is what I did.......

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

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[l]
format........thanks a lot

There are also some dictionary functions that can give you access to the inner sanctum:

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
"""
This question has already been answered. Start a new discussion instead.