title: How to increment counter in for loop for python?
body: <p>I'm just trying to increment a simple counter in my for loop, but this function always returns 54.  I'm guessing it does this because it sees the second counter as a local variable inside the for loop.  How can I increment the counter?? I feel like this should be really simple since python is supposedly a straight-forward language.  Any help would be greatly appreciated!</p>
  
  <pre><code>for line in train_instances:
      counter = 54
      a = (line.split(":")[0])[i]
      b = (line.split(":")[1])[1]
      if ((int(a) == X) and (int(b) == Y)):
          counter = counter + 1
  return counter
  </code></pre>