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 can use a dictionary comprehension (supported in Python 2.7+):</p>

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

python dictionary