小编joh*_*hns的帖子

python:在子列表中定位元素

给定这些子列表

lst=[['a', 'b', 'c', 'd', 'e'], ['f', 'g', 'h']]
Run Code Online (Sandbox Code Playgroud)

我试图找到其元素的位置,例如,字母“a”位于 0,0 但这一行

print(lst.index('a'))
Run Code Online (Sandbox Code Playgroud)

相反会产生以下错误: ValueError: 'a' is not in list

python nested-lists sublist

5
推荐指数
1
解决办法
379
查看次数

标签 统计

nested-lists ×1

python ×1

sublist ×1