相关疑难解决方法(0)

Python - 在列表列表中查找项目的索引

我有一份清单清单:

colours=[["#660000","#863030","#ba4a4a","#de7e7e","#ffaaaa"],["#a34b00","#d46200","#ff7a04","#ff9b42","#fec28d"],["#dfd248","#fff224","#eefd5d","#f5ff92","#f9ffbf"],["#006600","#308630","#4aba4a","#7ede7e","#aaffaa"]]
Run Code Online (Sandbox Code Playgroud)

什么是最清洁的搜索列表的方式,并返回其中一个项目的位置,例如"#660000"

我查看了索引方法,但似乎没有解压缩列表中的列表.

postion=colours.index("#660000")
Run Code Online (Sandbox Code Playgroud)

给出:ValueError: ['#660000'] is not in list,不像[0][0]我期望的那样......

python indexing list

14
推荐指数
3
解决办法
4万
查看次数

在嵌套列表python中查找字符串及其索引的所有出现

我有一个以下格式的嵌套列表:

[['john'],['jack','john','mary'],['howard','john'],['jude']...]
Run Code Online (Sandbox Code Playgroud)

我想找到嵌套列表中出现的前 3 或 5 个 john 索引(因为列表真的很长)并返回索引,例如: (0,0),(1,1),(2,1) 或采用任何建议的格式。

我对嵌套列表相当陌生。任何帮助将非常感激。

python nested-lists

2
推荐指数
1
解决办法
1383
查看次数

标签 统计

python ×2

indexing ×1

list ×1

nested-lists ×1