CS50 DNA pset6 only works with small.csv, not large.csv
I’m having troubles finishing this problem, when I include “temp = 0” on line 32, as it currently is, it doesn’t work at all, but when I remove it it only works on small.csv (plus I feel it is necessary anyways). Really confused with what logic is going wrong in this.
from sys import argv, exit
import csv
if len(argv) != 3:
print("Usage: python dna.py data.csv sequence.txt")
exit(1)
with open(argv[1], 'r') as csv_file:
csv_reader = csv.reader(csv_file)
for row in csv_reader:
header = row
header.pop(0)
break
dictionary = {}
for item in header:
dictionary[item] = 0
with open(argv[2], 'r') as dna_txt:
dna_reader = dna_txt.read()
for key in dictionary:
temp = 0
max_count = 0
for i in range(len(dna_reader)):
if dna_reader[i : i + len(key)] == key:
temp += 1
else:
if temp > max_count:
max_count = temp
temp = 0
i += len(key)
dictionary[key] = max_count
with open(argv[1], 'r') as file:
table = csv.DictReader(file)
for person in table:
count = 0
for dna in dictionary:
if int(dictionary[dna]) == int(person[dna]):
count += 1
else:
count = 0
if count == len(header):
print(person['name'])
exit(1)
print('No match')
exit(0)
Go to Source
Author: Will H.