【发布时间】:2021-07-21 14:03:32
【问题描述】:
我需要检查一个嵌套列表是否有一列具有相同的字符串
grid = [
["x", " ", "x"],
["x", " ", " "],
["x", "x", "x"]
]
#if grid has a column or row with the same string (such as the first column and last row) then it will say "yes"
我只对行做到了:
grid = [
["x", " ", "x"],
["x", " ", " "],
["x", " ", "x"]
]
print(grid)
row = ['x', 'x', 'x']
if row in grid:
print("Yes")
else:
print("no")
【问题讨论】:
-
我建议发布一个示例以及您迄今为止尝试过的内容
-
刚刚编辑了帖子以显示我到目前为止所做的事情(它只适用于行)
-
这能回答你的问题吗? python tic tac toe winning conditons
标签: python python-3.x list nested-lists