title: Why is this python loop containing consecutive duplicate items breaking?
body: <p>I am attempting solve <a href="https://www.codewars.com/kata/directions-reduction/train/python" rel="nofollow noreferrer">this</a> problem. In the problem am required to iterate over a list of directions (<code>NORTH, SOUTH, EAST, WEST</code>) and discard any adjacent opposite directions (<code>NORTH</code> and <code>SOUTH</code>, <code>EAST</code> and <code>WEST</code>) to return a reduced array containing only non-redundant directions. When I iterate over a list that does not contain consecutive duplicates, such as <code>["NORTH", "SOUTH", "SOUTH", "EAST", "WEST", "NORTH", "WEST"]</code>, my code works fine, but it breaks when I iterate over a list with consecutive duplicates, like <code>['EAST', 'EAST', 'WEST']</code>. Why is my code doing this, and how can I fix it to handle consecutive duplicates?</p>
  
  <pre><code>def dirReduc(arr):
    for direction in arr[:-1]:
      try:
        gotdata = arr[arr.index(direction)+1] 
      except IndexError:
        gotdata = 'null'
      except ValueError:
        gotdata = 'null'
      if gotdata is 'null':
        if arr == dirReduc(arr):
          return arr
        else:
          return dirReduc(arr)
      elif cancel_pair(direction, arr[arr.index(direction)+1]):
        del arr[arr.index(direction):arr.index(direction)+2]
    return arr
  
  def cancel_pair(dir1, dir2):
    if dir1 in ('NORTH') and dir2 in ('SOUTH') or dir1 in ('SOUTH') and dir2 in ('NORTH'):
      return True
    elif dir1 in ('WEST') and dir2 in ('EAST') or dir1 in ('EAST') and dir2 in ('WEST'):
      return True
    return False
  </code></pre>