def get_occurrences_of_sequence(original_dataset: [], checked_sequence: ()) -> []:
时间: 2024-06-04 08:12:21 浏览: 18
# function definition
def get_occurrences_of_sequence(original_dataset: [], checked_sequence: ()) -> []:
"""
This function takes in two parameters:
1. original_dataset: a list of tuples containing sequences of integers
2. checked_sequence: a tuple containing sequence of integers to be searched in the original_dataset
The function returns a list of tuples containing the index of the sequence in the original_dataset and the number of times the checked_sequence occurs in that sequence.
If the checked_sequence is not found in any of the sequences in the original_dataset, the function returns an empty list.
"""
occurrences_list = []
for i, sequence in enumerate(original_dataset):
# check if checked_sequence is a sub-sequence of sequence
if checked_sequence in [sequence[j:j+len(checked_sequence)] for j in range(len(sequence)-len(checked_sequence)+1)]:
# count the number of times checked_sequence occurs in sequence
count = sequence.count(checked_sequence)
# store the index of the sequence and the count of checked_sequence in a tuple
occurrences_list.append((i, count))
return occurrences_list
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)