Update a Value in Python
<p>Hello I am trying to write a program that reads a CSV file of different animals of various breeds. Various animals, named differently, can be of the same breed. (Imagine two cats named bob and sam)</p>

<p>The breeds are in one column and the names are in another.</p>

<p>I want to be able to go over all the animals and count the number of animals in each breed.</p>

<p>The code I have so far is like this:</p>

<pre><code>dragon = open('dragons.csv')

breed = {}

for line in dragon:
    row = line.strip().split(',')
    if row[4] in breed.keys():

else:
    breed[row[4]] = 1 #The Breed is in the fourth column
</code></pre>

<p>How can I do this?</p>

<p>Thank you!</p>

<p>Your <code>else</code> block is insufficiently indented (<code>else</code> can pair with <code>for</code>, but it's uncommon, and the logic of your code says its an error here).</p>

<p>Even if you fix that though, you can't have an empty block in Python, because Python needs at least one indented line of code to detect the indentation level of the block (to allow it to detect when the block ends). When you don't provide any body for a block (start a new block immediately, or end the outer block before providing a body), you get the "expected an indented block" error you mention. So you can either use <code>pass</code> (the no-op keyword that means "Here is something to put in a block that doesn't do anything):</p>

<pre><code>if row[4] in breed:  # Don't call .keys(); much slower on Py2, a little slower on Py3
    pass
else:
    breed[row[4]] = 1 #The Breed is in the fourth column
</code></pre>

<p>Or just invert the <code>if</code> test to control the <code>else</code> block so you don't need both:</p>

<pre><code>if row[4] not in breed:
    breed[row[4]] = 1 #The Breed is in the fourth column
</code></pre>

python arrays csv dictionary