pythonic way of initialization of dict in a for loop
<p>Is there a python way of initialization of a dictionary?</p>

<pre><code>animals = ["dog","cat","cow"]
for x in animals:
    primers_pos[x]={}
</code></pre>

<p>Is there something like</p>

<pre><code>(primers_pos[x]={} for x in animals)
</code></pre>

<p>You may also use <em>collections.defaultdict</em></p>

<pre><code>primer_pos = defaultdict(dict)
</code></pre>

<p>Then whenever you reference <em>primer_pos</em> with a new key, a dictionary will be created automatically</p>

<pre><code>primer_pos['cat']['Fluffy'] = 'Nice kitty'
</code></pre>

<p>Will by chain create <em>{'Fluffy': 'Nice Kitty'}</em> as value of key 'cat' in dictionary <em>primer_pos</em></p>

python dictionary