简体   繁体   English

使用迭代变量检查dict键的值?

[英]Use iterating variable to check value of dict key?

here is my code 这是我的代码

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")

What I want to be able to do, is on line 8, check if tile is the same as index, and also check the value of the key(this part is the ********) 我想要做的是在第8行上,检查tile是否与index相同,并检查key的值(这部分是********)

Basically I want to use the iterating variable index to request and check the value of the key that is the same as index . 基本上,我想使用迭代变量index来请求和检查与index相同的键的值。 This might look like 这可能看起来像

if int(tile) == index and check[?index?] == False:

Please help and I am more than wiling to explain further as I am not very good at explaining these kind of things. 请帮助,我不愿意进一步解释,因为我不太擅长解释这类事情。

Try: 尝试:

if int(tile) == index and not check[str(index)]:

There are chances that tile is already an integer (if you entered one). tile有可能已经是整数(如果输入了整数)。 Keys of check are strings. check是字符串。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM