[英]Finding all combinations of a list of numbers without the pair being the same in python
[英]Finding where a pair of numbers are located in a list of lists in Python?
我有一個清單清單,例如
[["text",[6,24,4,40],[12,6,11,10],[...]]]
我希望能夠找出一對數字的位置,例如[4,40],但我只需要它在整個列表中的位置,因此在這種情況下,它將是0(不包括“文本”)。 即對於此示例,我想知道列表[6,24,4,40]的位置?
到目前為止,我只能用一個數字而不是一對數字來做到這一點。
def subfind(needle, haystack):
"""Returns index if found, None otherwise."""
length = len(needle)
index = 0
for item in haystack:
if isinstance(item, list):
for ee in xrange(0, len(item) - length + 1):
if item[ee:ee+length] == needle:
return index
index += 1
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.