Python 如何在列表中搜索统一在单个字符串中的多个元素并返回位置?

Python 如何在列表中搜索统一在单个字符串中的多个元素并返回位置?,python,python-3.x,string,list,Python,Python 3.x,String,List,我的清单如下: ['56','33 f6','39 74 24 0c','57','74 07','68 1c e0 40 00','eb 05','68 18 e0 40 00','68 10 e0 40 00','ff 15 18 81 40 00','8b f8','59','3b fe','59','75 04','33 c0'] 假设我想搜索一个序列,如下所示: '33 f6 39 74 24 0c 57 74'然后知道列表中的哪些元素被涵盖。在这种情况下,它将是位置2,3,4,5

我的清单如下:

['56','33 f6','39 74 24 0c','57','74 07','68 1c e0 40 00','eb 05','68 18 e0 40 00','68 10 e0 40 00','ff 15 18 81 40 00','8b f8','59','3b fe','59','75 04','33 c0']
假设我想搜索一个序列,如下所示:

'33 f6 39 74 24 0c 57 74'
然后知道列表中的哪些元素被涵盖。在这种情况下,它将是位置2,3,4,5

我想把列表统一成一个字符串,然后通过
find()
进行搜索。但我不知道如何前进

在Python中有更好的方法来实现这一点吗


编辑:接受的解决方案工作得很好

我能想到的最短版本:

arr = ['56', '33 f6', '39 74 24 0c', '57', '74 07', '68 1c e0 40 00', 'eb 05', '68 18 e0 40 00', '68 10 e0 40 00', 'ff 15 18 81 40 00', '8b f8', '59', '3b fe', '59', '75 04', '33 c0']
search_term = '33 f6 39 74 24 0c 57 74'
joined = ' '.join(arr)
search_index = joined.find(search_term)
contained_indices = []
counter = 0
for i in range(len(arr)):
    if counter >= search_index and counter <= search_index + len(search_term):
        contained_indices.append(i)
    if counter >= search_index + len(search_term):
        break
    counter += len(arr[i])+1

print(contained_indices)
arr=['56','33 f6','39 74 24 0c','57','74 07','68 1c e0 40 00','eb 05','68 18 e0 40 00','68 10 e0 40 00','ff 15 18 81 40 00','8b f8','59','3b fe','59','75 04','33 c0']
搜索词='33 f6 39 74 24 0c 57 74'
联接=“”。联接(arr)
search\u index=joined.find(搜索词)
包含的索引=[]
计数器=0
对于范围内的i(len(arr)):
如果计数器>=搜索索引且计数器=搜索索引+len(搜索项):
打破
计数器+=len(arr[i])+1
打印(包含索引)
请注意,它使用基于0的索引,如果当前数组中没有整洁的结构,它可能会失败