Complex transforming nested dictionaries into objects in python
<p><br>
It hasn't been long since I started learning python, but I really want to dig in it. And dig it hard. So here is a task I've been studying for a while but haven't cracked yet:<br>
I am given a mixed combination of nested dictionaries and lists (let's call it "<strong>combination</strong>"), and I need to implement <em>function</em> that will allow accessing nested elements as object attributes, also somehow treating <strong>combination</strong> elements as iterable. This should look something like this:  </p>

<pre><code>combination = {
'item1': 3.14,
'item2': 42,
'items': [
         'text text text',
         {
             'field1': 'a',
             'field2': 'b',
         },
         {
             'field1': 'c',
             'field2': 'd',
         },
         ]
}

def function(combination):
    ...
</code></pre>

<p>so that<br>
<code>list(function(combination).items.field1)</code>
will give: <code>['a', 'c']</code>, and<br>
<code>list(function(combination).item1)</code> will give: <code>[3.14]</code>.<br>
<strong>Edit</strong> As mentioned by @FM, I missed description of handling non-dict elements:
<code>list(function(combination).items[0])</code> >>> <code>['text text text']</code></p>

<hr>

<p>I tried implementing a class (kudos to <a href="http://stackoverflow.com/questions/1305532/convert-python-dict-to-object/1305663#1305663">Marc</a>) to help me:</p>

<pre><code>class Struct:
    def __init__(self, **entries): 
        self.__dict__.update(entries)
</code></pre>

<p>and then using it in the <em>function</em> like <code>return Struct(**combination)</code><br>
While being very nifty, it is only the first step to the desired result.<br>
But as the next step needs to go deeper, it overwhelms me and I can't make it on myself.<br>
Therefore, I kindly ask for your help.  </p>

<p>Michael.</p>
