I have read some documentation about python, but no examples on how could you can extract Keys from a double dictionary.
To understand better here is an example:

Let's say we have the following dictionary:

{'AAA':  {'KEY1':'text1', 'KEY2':'text2', 'KEY3:' 'text3', 'KEY4': 'text4'},
'BBB':   {'BBB1':{'KEY1':'text1', 'KEY2':'text2', 'KEY3:' 'text3', 'KEY4': 'text4'},
            'BBB2':{'KEY1':'text1', 'KEY2':'text2', 'KEY3:' 'text3', 'KEY4': 'text4'},
            'BBB3':{'KEY1':'text1', 'KEY2':'text2', 'KEY3:' 'text3', 'KEY4': 'text4'}}}

How can i extract KEY1, KEY2 and KEY 4 from AAA and KEY3 KEY4 from BBB1, BBB2, BBB3 in BBB?

Recommended Answers

All 2 Replies

you do it systematically using the same way to read single level dict

d={'AAA': {'KEY1':'text1', 'KEY2':'text2', 'KEY3': 'text3', 'KEY4': 'text4'},
'BBB': {'BBB1':{'KEY1':'text1', 'KEY2':'text2', 'KEY3': 'text3', 'KEY4': 'text4'},
'BBB2':{'KEY1':'text1', 'KEY2':'text2', 'KEY3': 'text3', 'KEY4': 'text4'},
'BBB3':{'KEY1':'text1', 'KEY2':'text2', 'KEY3': 'text3', 'KEY4': 'text4'}}}

for i,j in d.iteritems():
    for m,n in j.iteritems():
        print m,n

do the checking of "AAA", "BBB" yourself.

Sorry for late delay, i have manage to get the info from dictionary.
And, yeah, silly me, the "for" loop seems to do the job with some other functions on dictionaries...like, has_key, get, iterkeys...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.