Second level looping over dictionaries
<p>In building a class with an out line like below I would like the behaviour of  the for loops to, if done once: just give the keys as normal an then move on to the next line of code. But if a second loop is set up inside the first loop it would give the keys on the first loop and then ea value in the sequences in the second loop.  The problem I can't figure out is how to set up this under <strong>iter</strong>.     </p>

<pre><code>class MyClass():
    def __init__(self):
        self.cont1 = [1,2,3,4]
        self.cont2 = ('a','b','c')

def __iter__(self):
    pass # ???????
</code></pre>

<p>Something like this:</p>

<pre><code>dct = dict(container1=[5,6,7,8], container2=('a','b','c')

if one loop is used:

   for ea in dct:
        print(ea)
print("Howdy")

'containter1'
'containter2'
Howdy
</code></pre>

<p>If a nest loop is used:</p>

<pre><code>for ea in dct:
    print(ea)
    for i in dct.get(ea):
        print(i)

'container1'
5
6
...
'container2'
a
b
c
</code></pre>

<p>You can do this with a second class like this</p>

<pre><code>class MyClass():
    def __init__(self):
        self.data  = [MyClass2({'cont1' : [1,2,3,4]}),MyClass2({'cont2' : ('a','b','c')})]    

    def __iter__(self):
        for item in self.data:
            yield item



class MyClass2():
    def __init__(self, mydict):
        self.d = mydict

    def __iter__(self):
        for item in self.d.values():
            for value in item:
                yield value

    def __repr__(self):
        return(list(self.d.keys())[0])


    m = MyClass()

for k in m:
    print(k)
    for val in k:
        print(val)
</code></pre>

python class for-loop