Example solution for pattern_count() and reading from a dataset
Completion requirements
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))
Last modified: Thursday, 2 April 2020, 4:22 PM