0

This is my code for pset6 -> dna, it gives successful output for some test cases while fails for others. Please help!

from sys import argv, exit
import csv

if len(argv) != 3:
    print("Usage: python dna.py data.csv sequence.txt")
    exit(1)

# csv_file = argv[1]
# text_file = argv[2]
dicts = []

with open(argv[1]) as csvfile :
    temp_read = csv.DictReader(csvfile, delimiter = ',')
    for row in temp_read :
        dicts.append(dict(row))
    
text_file = open(argv[2], 'r')
Lines = text_file.readlines()
lines = Lines[0]

text_file.close()

for d in dicts :
    
    STR = []
    match_str = {}
    
    for keys in d.keys():
        STR.append(keys)
        
    STR.remove('name')
        
    for i in STR:
        count = 0 
        count = lines.count(i)
        match_str[i] = count
        
    for string in STR:
        if int(d[string]) == match_str[string]:
            k = 1;
        else:
            k = 2;

    if k == 1:
        print(d['name'])
        exit(0)
            
print("No match")

You must log in to answer this question.

Browse other questions tagged .