[英]Use iterating variable to check value of dict key?
这是我的代码
tiles = [" a ", " b ", " c ", " d ", " e ", " f ", " g ", " h ", " i "]
check = {'0': False, '1': False, '2': False, '3': False, '4': False, '5': False,
'6': False, '7': False, '8': False}
tile = input("Player 1: What tile?")
for index, z in enumerate(tiles):
if int(tile) == index and ********:
tiles[index] = str("xxxxx")
我想要做的是在第8行上,检查tile是否与index相同,并检查key的值(这部分是********)
基本上,我想使用迭代变量index
来请求和检查与index
相同的键的值。 这可能看起来像
if int(tile) == index and check[?index?] == False:
请帮助,我不愿意进一步解释,因为我不太擅长解释这类事情。
尝试:
if int(tile) == index and not check[str(index)]:
tile
有可能已经是整数(如果输入了整数)。 check
是字符串。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.