![](/img/trans.png)
[英]how to conditionally (value in column) search for substrings in another column in python loop
[英]Python: How to search in first column of nested loop?
我有这样的清单:
[
[1, 37, 79, 164, 155, 32, 87, 39, 113, 15, 18, 78, 175, 140, 200, 4, 160, 97, 191, 100, 91, 20, 69, 198, 196],
[2, 123, 134, 10, 141, 13, 12, 43, 47, 3, 177, 101, 179, 77, 182, 117, 116, 36, 103, 51, 154, 162, 128, 30],
[3, 48, 123, 134, 109, 41, 17, 159, 49, 136, 16, 130, 141, 29, 176, 2, 190, 66, 153, 157, 70, 114, 65, 173, 104, 194, 54]
]
我想在第一列中找到搜索值的列表项的索引。
例如,如果我搜索2 ,它应该返回我1,因为2位于列表索引1的第一列中。
我如何在python中实现呢?
>>> [i for i, row in enumerate(data) if row[0] == 2]
[1]
>>> data = [
[1, 2, 3],
[2, 3, 4],
[1, 3, 5],
[2, 6, 8]
]
>>> [i for i, row in enumerate(data) if row[0] == 2]
[1, 3]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.