Example solution for pattern_count() and reading from a dataset
Requisitos de finalización
def pattern_count(sequence, pattern):
count = 0
for i in range(len(sequence) - len(pattern) +1):
if sequence[i:i+len(pattern)] == pattern:
count += 1
return count
# the path to the dataset is the first argument
import sys
dataset_file = sys.argv[1]
with open(dataset_file) as f:
sequence = f.readline()[:-1]
pattern = f.readline()[:-1]
print(pattern_count(sequence, pattern))
Última modificación: jueves, 2 de abril de 2020, 16:22