【发布时间】:2022-10-14 23:07:17
【问题描述】:
known_cards = self.hand[self.known_index]
最终给出错误
TypeError:列表索引必须是整数或切片,而不是列表
这里的输入将类似于以下内容
self.hand = [4,2,7,9] self.known_index = [0,3] known_cards = [4,9] # the 0th and 3rd index of self.hand我知道使用循环会很容易解决,但是有没有更好的方法呢?
【问题讨论】:
-
known_cards = [self.hand[x] for x in self.known_index]
标签: python