这是我的密码:
test_list= [
["Romeo and Juliet","Shakespeare"],
["Othello","Play"],
["Macbeth","Tragedy"]
]
value = "Tragedy"
print(test_list.index(value))
结果我得到“ValueError:'悲剧'不在列表中
我的结论是,索引只对一维数组有效?但是我该怎么做呢?如果我把数组设为1D,这段代码可以很好地工作。请帮忙,但简单地说,因为我是初学者。你知道吗
很抱歉在手机上出现格式化问题。这个阵列对我来说是正确的。你知道吗
也可以使用映射运算符:
也可以使用
numpy
:输出:
如果一个元素有多个引用,那么
np.where
将给出所有引用的索引列表。你知道吗循环浏览列表并在每个子列表中搜索字符串。你知道吗
相关问题 更多 >
编程相关推荐