Append to dictionary in defaultdict
<p>I have a defaultdict, I want to create a dictionary as the value part, can I append to this dictionary? At the moment I am appending to a list which means that the dictionaries are separated. </p>

<pre><code>dates = [datetime.date(2016, 10, 17), datetime.date(2016, 10, 18), datetime.date(2016, 10, 19), datetime.date(2016, 10, 20), datetime.date(2016, 10, 21), datetime.date(2016, 10, 22), datetime.date(2016, 10, 23)]

e = defaultdict(list)
for key, value in d.iteritems():
    value = (sorted(value, key=itemgetter('date'), reverse=False))
    for date in dates:
        for i in value:
            if i['date'] == str(date) and i['time'] == 'morning':
                value1 = float(i['value1'])
                temp = {'val_morning': value1 }
                e[str(date)].append(temp)
            elif ii['date'] == str(date) and i['time'] == 'evening':
                value2 = float(i['value2'])
                temp = {'val_evening': value2 }
                e[str(date)].append(temp)
</code></pre>

<p>which results in:</p>

<pre><code>{'2016-10-20': [{'val_morning': 0.0}, {'val_evening': 0.0}], '2016-10-21': [{'val_morning': 0.0}, {'val_evening': 0.0}]}
</code></pre>

<p><strong>Edit</strong>
desired output:</p>

<pre><code>{                        
    '2016-10-20': {'val_morning': 0.0, 'val_evening': 0.0}, 
    '2016-10-21': {'val_morning': 0.0, 'val_evening': 0.0}
}
</code></pre>

<p>if i understand correctly</p>

<pre><code>import datetime
dates = [datetime.date(2016, 10, 17), datetime.date(2016, 10, 18), datetime.date(2016, 10, 19), datetime.date(2016, 10, 20), datetime.date(2016, 10, 21), datetime.date(2016, 10, 22), datetime.date(2016, 10, 23)]

dict_x = {}
for i in map(str,set(dates)):
    dict_x[i] = {'val_morning': 0.0, 'val_evening': 0.0}

dict_x

output :
{'2016-10-17': {'val_evening': 0.0, 'val_morning': 0.0},
 '2016-10-18': {'val_evening': 0.0, 'val_morning': 0.0},
 '2016-10-19': {'val_evening': 0.0, 'val_morning': 0.0},
 '2016-10-20': {'val_evening': 0.0, 'val_morning': 0.0},
 '2016-10-21': {'val_evening': 0.0, 'val_morning': 0.0},
 '2016-10-22': {'val_evening': 0.0, 'val_morning': 0.0},
 '2016-10-23': {'val_evening': 0.0, 'val_morning': 0.0}}
</code></pre>

python defaultdict