我有一个列表的列表:
colours = [["#660000","#863030","#ba4a4a","#de7e7e","#ffaaaa"],["#a34b00","#d46200","#ff7a04","#ff9b42","#fec28d"],["#dfd248","#fff224","#eefd5d","#f5ff92","#f9ffbf"],["#006600","#308630","#4aba4a","#7ede7e","#aaffaa"]]
最干净的搜索列表并返回其中一项的位置的方法是什么,例如"#660000"
?
我查看了 index
方法,但似乎无法解开列表中的列表。
postion = colours.index("#660000")
输出结果为:ValueError: ['#660000'] is not in list
,而不是我期望的[0][0]
。
if c in colour
然后调用colour.index(c)
的想法,对我来说有点浪费。 - Rik PoggiValueError: list.index(x): x not in list
异常。 - Burhan Khalid