Extract results from a dictionary
<p>I have a dictionary as follows:</p>

<pre><code>  D = { "America": { "Washington": { "Seattle": ('park', 'museum'), "Kent": ("market",) }, 'Colorado': { "Boulder": ("hiking",) } } }
</code></pre>

<p>how can I make the following results using that dictionary.</p>

<pre><code>America Wahington Seattle park
America Wahington Seattle museum
America Wahington Kent market
America Colorado Boulder hiking
</code></pre>

<p>I tried as follows:</p>

<p>for x in D.iteritems():
    print x</p>

<p>Could not figure out how to extract each elements after that.
Alos wan to to how is the good way of getting the above result.</p>

<p>This versions should be more readable for you. But they are not so universal like other versions.</p>

<pre><code>for country in D:
    for state in D[country]:
        for city in D[country][state]:
            for place in D[country][state][city]:
                print(country, state, city, place)


for country, A in D.items():
    for state, B in A.items():
        for city, C in B.items():
            for place in C:
                print(country, state, city, place)
</code></pre>

python python-2.7 dictionary