Q:

Python Connect four Diagonal Checking

I'm having issue getting my code started. I have a Connect 4 project for my programming class and I'm having a really stupid issue. I don't understand the diagonal checking. He gave us an example but I honestly don't get it.
def CheckForWinner(board, playerName, playerChar):

diagonal = board[2][0] + board[3][1] + board[4][2] + board[5][3]
if playerChar * 4 in diagonal:
    return playerName

It is a 42 space board(7x6)
 1 2 3 4 5 6 7 
 _ _ _ _ _ _ _ 
|_|_|_|_|_|_|_|
|_|_|_|_|_|_|_|
|_|_|_|_|_|_|_|
|_|_|_|_|_|_|_|
|_|_|_|_|_|_|_|
|_|_|_|_|_|_|_|

I'm just having difficulties under standing what it is checking. I'm not asking for you to give me the code. Just an explanation please. :)

A:

It's building a string up of the characters stored in a diagonal. For example, if the board is:
 1 2 3 4 5 6 7 
 _ _ _ _ _ _ _ 
|_|A|_|_|_|_|_|
|_|_|B|_|_|_|_|
|_|_|_|C|_|_|_|
|_|_|_|_|D|_|_|
|_|_|_|_|_|_|_|
|_|_|_|_|_|_|_|

Then the following line:
diagonal = board[2][0] + board[3][1] + board[4][2] + board[5][3]

will assign the value ABCD to the variable diagonal, because it's concatenating the characters in board[2][0] (A), board[3][1] (B), etc... into one string: ABCD.
The if statement makes up a 4-character string of the player's character, and checks if it is in the diagonal string. If the player's character is X, for example, then the if evaluates to checking if XXXX is in ABCD. It will then return the player's name if this is True, which means they've won.
(Of course, the actual location of the A, B, C and D in my example depends on what way round the list of lists is representing the board)

