首页 > 解决方案 > 列表中的字典。返回字典名称

问题描述

我正在使我的第一个项目成为井字游戏。我有以下内容:

the_board = {'1 3': ' ' , '2 3': ' ' , '3 3': ' ' ,
            '1 2': ' ' , '2 2': ' ' , '3 2': ' ' ,
            '1 1': ' ' , '2 1': ' ' , '3 1': ' ' }
        
wins = [[the_board['1 3'],the_board['2 3'],the_board['3 3']],
            [the_board['1 2'],the_board['2 2'],the_board['3 2']],
            [the_board['1 1'],the_board['2 1'],the_board['3 1']],
            [the_board['1 3'],the_board['1 2'],the_board['1 1']],
            [the_board['2 3'],the_board['2 2'],the_board['2 1']],
            [the_board['3 3'],the_board['3 2'],the_board['3 1']],            
            [the_board['1 3'],the_board['2 2'],the_board['3 1']],
            [the_board['1 1'],the_board['2 2'],the_board['3 3']]]

有什么方法可以在我输入wins[0][0]时打印出来"the_board['1 3']"吗?然后我可以分配一个"X"tothe_board['1 3']吗?

谢谢

标签: pythonlistdictionary

解决方案


推荐阅读