简体   繁体   English

多维字符串数组

[英]Multi-Dimensional String Arrays

Trying to develop a text based Hangman game in Python and want to use multi arrays to hold the words to guess but separated into individual letters.尝试在 Python 中开发基于文本的 Hangman 游戏,并希望使用多个数组来保存要猜测的单词但将其分成单个字母。

I'm currently getting this error: TypeError: list indices must be integers or slices, not tuple .我目前收到此错误: TypeError: list indices must be integers or slices, not tuple

Any ideas?有任何想法吗?

 words = [['d', 'u', 'c', 'k'],
      [],
      [],
      [],
      []]

My thought would be that if I ask to print array 1, 1 then I would get back "d" ?我的想法是,如果我要求打印数组 1, 1 那么我会得到"d"吗?

if i ask to print array 1, 1 then i would get back "d"?如果我要求打印数组 1, 1 那么我会得到“d”?

No that would return an error, as arrays start at 0.不,会返回错误,因为数组从 0 开始。

So you must return words[0][0], that would get you back "d".所以你必须返回words[0][0],这会让你回到“d”。

将您的列表索引为words[j][i]而不是words[i, j]

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

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