我需要能夠計算有多少字符串「O」的是在我的名單計數元素
top_board = [
[None, None, None, None, None, None, None, None, None],
[None, None, None, None, None, None, None, None, None],
[None, None, None, None, None, None, None, None, None],
[None, None, None, None, None, None, None, None, None],
[None, None, None, None, None, None, None, None, None],
[None, None, None, None, None, None, None, None, None],
[None, None, None, None, None, None, None, None, None],
[None, None, None, None, None, None, None, None, None],
[None, None, None, None, None, None, None, None, None]
]
後,我添加元素,如「O」和「X」,將看這樣
top_board = [
["O", None, None, None, None, None, None, None, None],
[None, None, None, None, None, None, None, None, None],
[None, None, None, None, None, "O", None, None, None],
[None, None, None, None, None, None, None, "O", None],
[None, None, None, None, None, None, None, None, None],
[None, None, None, None, None, None, None, None, None],
[None, None, None, "O", None, None, None, None, None],
[None, None, None, None, None, None, None, None, None],
[None, None, None, None, None, None, None, None, None]
]
現在我需要檢查是否有在我的列表中的「O」 0的功能,如果有,然後打印東西
你能說清楚你想要什麼嗎?請檢查top_board的任何列表中是否沒有「O」?或者每個列表是否沒有「O」?也就是'sum([lst.count('O')for top_board]]'或'[sum(1 for j in i if if ==「O」)for top_board]'? – fredtantini