Create dictionary with join in python
<p>Each row of my document contains a dictionary of informations :</p>

<pre><code>{'O':34, 'D': 75, '2015-01':{'c':30,'f':90},'2016-01':{'c':100,'f':78,'r':90.5}}
</code></pre>

<p>The expected is :</p>

<pre><code>{'2015-01,c':30,'2015-01,f':90,'2016-01,c':100....}
</code></pre>

<p>I tried this in python :</p>

<pre><code>for row in cursor:
       d = dict((''.join([l,',',row[l].keys()]),row[l].values())
                     for l in row.keys - ['O','D'])
</code></pre>

<p>But I got this error :
TypeError: sequence item 2: expected str instance, dict_keys found
Any help please.
Thank you</p>

<p>I suggest this :</p>

<pre><code>row = {'O':34, 'D': 75, '2015':{'c':30,'f':90},'2016':{'c':100,'f':78,'r':90.5}}
dic = {}

for key in row :
    if key != 'O' and key != 'D':
        subdic = row[key]
        for subkey in subdic :
            dic[key+","+subkey] = subdic[subkey]

print dic
</code></pre>

python dictionary join