title: Is there a way to check a diagonal of a 2 dimentional array in Python which has a variable size?
body: <p>I am currently programming a Connect N game in Python based on a Connect 4 logic (the game where you need 4 pieces in a row to win). I coded basically the Connect 4 function but having some hard time to make it work with an n-dimension win condition.</p>
  
  <p>I need to basically check for horizontal, vertical, positive slope, and negative slope diagonals which have 4 of the same pieces in a row. For my Connect 4 logic I have the following:</p>
  
  <pre><code>def winning_move(board, player_number):
      # Check horizontal locations for win
      for c in range(COLUMN_COUNT-3):
          for r in range(ROW_COUNT):
              if board[r][c] == player_number and board[r][c+1] == player_number and board[r][c+2] == player_number and board[r][c+3] == player_number:
                  return True
  
      # Check vertical locations for win
      for c in range(COLUMN_COUNT):
          for r in range(ROW_COUNT-3):
              if board[r][c] == player_number and board[r+1][c] == player_number and board[r+2][c] == player_number and board[r+3][c] == player_number:
                  return True
  
      # Check positively sloped diaganols
      for c in range(COLUMN_COUNT-3):
          for r in range(ROW_COUNT-3):
              if board[r][c] == player_number and board[r+1][c+1] == player_number and board[r+2][c+2] == player_number and board[r+3][c+3] == player_number:
                  return True
  
      # Check negatively sloped diaganols
      for c in range(COLUMN_COUNT-3):
          for r in range(3, ROW_COUNT):
              if board[r][c] == player_number and board[r-1][c+1] == player_number and board[r-2][c+2] == player_number and board[r-3][c+3] == player_number:
                  return True
  </code></pre>
  
  <p>With my limited knowledge, I thought about having a for loop to iterate with, but I can't have a for loop as a condition to an if. So I thought that there might be a way to check for a certain range of a matrix but couldn't find anywhere yet how I would do it.</p>
  
  <p>Is there a way to basically check for a range window inside a matrix without using for loops?</p>
  
  <p>Thanks in advance.</p>