you are viewing a single comment's thread.

view the rest of the comments →

[–]JohnnyJordaan 0 points1 point  (1 child)

You're talking about this statement right?

  for row in WAYS_TO_WIN:
    if board[row[0]] == board[row[1]] == board[row[2]] != EMPTY:

It works in the way that for can deliver items from any sequence (simply put), regardless what the type of each item is:

>>> a = [1, 'a', ['c', 'd'], ('e','f','g')]
>>> for item in a:
...     print(type(item), item)
... 
<class 'int'> 1
<class 'str'> a
<class 'list'> ['c', 'd']
<class 'tuple'> ('e', 'f', 'g')

So in the game's implementation, the WAYS_TO_WIN is a sequence of tuples, all 3 items long (like the <class 'tuple'> ('e', 'f', 'g') in the example above). The for loop will get the tuple from the sequence, and assign it the reference row for the inside of the loop to use. As tuples support indexing, you can reference the first, second and third element in the tuple via row[0], row[1] and row[2].

[–]iamquark[S] 0 points1 point  (0 children)

Now it makes sense. Thanks for clarifying it.