拜托,我需要帮助找出我的数组中的序列是否存在于另一个数组中,但我需要知道相同的序列被发现了多少次。我有这个,但只有找到一次才会返回。
mylist = ['A','V','V']
# this array contains the sequence 'A','V','V' twice:
listfull = ['A','V','V','V','V','V','E','A','V','V']
n = len(mylist )
return any(mylist == listfull [i:i + n] for i in range(len(listfull )-n + 1))
但我需要的是知道它在列表中出现了多少次
尝试此代码
mylist = ['A', 'V', 'V']
listfull = ['A', 'V', 'V', 'V', 'V', 'V', 'E', 'A', 'V', 'V']
n = len(mylist)
count = 0
for i in range(len(listfull) - n + 1):
if mylist == listfull[i:i + n]:
count += 1
print(count)