Skip to content

Commit 48f78ef

Browse files
author
暮晨
committed
EX.A tic-tac-toe where X wins in the first attempt
1 parent 5511533 commit 48f78ef

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ So, here we go...
3232
- [> For what?/为什么?](#-for-what为什么)
3333
- [> Evaluation time discrepancy/评估时间差异](#-evaluation-time-discrepancy评估时间差异)
3434
- [> `is` is not what it is!/出人意料的`is`!](#-is-is-not-what-it-is出人意料的is)
35-
- [> A tic-tac-toe where X wins in the first attempt!](#-a-tic-tac-toe-where-x-wins-in-the-first-attempt)
35+
- [> A tic-tac-toe where X wins in the first attempt!/一蹴即至!](#-a-tic-tac-toe-where-x-wins-in-the-first-attempt一蹴即至)
3636
- [> The sticky output function](#-the-sticky-output-function)
3737
- [> `is not ...` is not `is (not ...)`](#-is-not--is-not-is-not-)
3838
- [> The surprising comma](#-the-surprising-comma)
@@ -504,12 +504,12 @@ True
504504
505505
---
506506
507-
### > A tic-tac-toe where X wins in the first attempt!
507+
### > A tic-tac-toe where X wins in the first attempt!/一蹴即至!
508508
509509
```py
510-
# Let's initialize a row
510+
# 我们先初始化一个变量row
511511
row = [""]*3 #row i['', '', '']
512-
# Let's make a board
512+
# 并创建一个变量board
513513
board = [row]*3
514514
```
515515
@@ -526,19 +526,19 @@ board = [row]*3
526526
[['X', '', ''], ['X', '', ''], ['X', '', '']]
527527
```
528528
529-
We didn't assign 3 "X"s or did we?
529+
我们有没有赋值过3"X" 呢?
530530
531-
#### 💡 Explanation:
531+
#### 💡 说明:
532532
533-
When we initialize `row` variable, this visualization explains what happens in the memory
533+
当我们初始化 `row` 变量时, 下面这张图展示了内存中的情况。
534534
535535
![image](/images/tic-tac-toe/after_row_initialized.png)
536536
537-
And when the `board` is initialized by multiplying the `row`, this is what happens inside the memory (each of the elements `board[0]`, `board[1]` and `board[2]` is a reference to the same list referred by `row`)
537+
而当通过对 `row` 做乘法来初始化 `board` 时, 内存中的情况则如下图所示 (每个元素 `board[0]`, `board[1]` `board[2]` 都和 `row` 一样引用了同一列表.)
538538
539539
![image](/images/tic-tac-toe/after_board_initialized.png)
540540
541-
We can avoid this scenario here by not using `row` variable to generate `board`. (Asked in [this](https://github.com/satwikkansal/wtfpython/issues/68) issue).
541+
我们可以通过不使用变量 `row` 生成 `board` 来避免这种情况. ([这个](https://github.com/satwikkansal/wtfpython/issues/68)issue提出了这个需求.)
542542
543543
```py
544544
>>> board = [['']*3 for _ in range(3)]

0 commit comments

Comments
 (0)