Remove the function and command from the output
<p>I have trying out defaultdict with lamba function. However, I could not get the output I want. I will demonstrate with more details. Below is my code:</p>

<pre><code>from collections import defaultdict

the_list = [
    ('Samsung', 'Handphone', 10), 
    ('Samsung', 'Handphone', -1), 
    ('Samsung', 'Tablet', 10),
    ('Sony', 'Handphone', 100)
]

d = defaultdict(lambda: defaultdict(int))

for brand, thing, quantity in the_list:
    d[brand][thing] += quantity
</code></pre>

<p>My result is:</p>

<pre><code>defaultdict(&lt;function &lt;lambda&gt; at 0x02715C70&gt;, {'Sony': defaultdict(&lt;type 
'int'&gt;, {'Handphone': 100}), 'Samsung': defaultdict(&lt;type 'int'&gt;, {'Handphone': 
9, 'Tablet': 10})})
</code></pre>

<p>I want my result to be this:</p>

<pre><code>{
    'Samsung': {
        'Handphone': 9, 
        'Tablet': 10
    },
    'Sony': {
        'Handphone': 100
    }
}
</code></pre>

<p>How am I supposed to do remove the <code>defaultdict(&lt;function &lt;lambda&gt; at 0x02715C70&gt;, {'Sony': defaultdict(&lt;type int'&gt;,</code> to achieve my desired output. Thank you!</p>

<p>Try dumping your data in JSON format if you want to remove the type information. </p>

<p><p> Insert this at the top:</p>

<pre><code>import json
</code></pre>

<p>And this at the bottom:</p>

<pre><code>print json.dumps(d, indent=4)
</code></pre>

<p>And your code should print out like this:</p>

<pre><code>{
    "Sony": {
        "Handphone": 100
    }, 
    "Samsung": {
        "Handphone": 9, 
        "Tablet": 10
    }
}
</code></pre>

<p>This will serve as a solution if order does not matter.</p>

python defaultdict