0
    import csv
    import sys
    
    with open(sys.argv[1], 'r') as file:
        # stores data from small.csv in both dict and list form
        dna_names_dict = csv.DictReader(file)
        dna_names_list = csv.reader(file)
        # gets all str sequences from the first row of the list csv file
        row_0 = next(dna_names_list)
        strlist = []
        for strsequence in range(1, len(row_0), 1):
            strlist.append(row_0[strsequence])
    # make dict of str from list
    dictofstr = { i : 0 for i in strlist}
    # open dna sequence
    with open(sys.argv[2], 'r') as dna:
        dnasequence = dna.read()
    
    # count repeats of str in dna sequence
    # for every str
    for each_str in strlist:
        # for every character in dna, goes through each combination
        for dna_char in range(0, len(dnasequence) - (len(each_str) - 1), 1):
            dna_block = []
            # make a block of the dna with same size as str from the position in the sequence
            for i in range(0, len(each_str), 1):
                dna_block.append(dnasequence[dna_char + i])
            # once it matches a combination it finds how many times the str repeats
            if ''.join(dna_block) == each_str:
                count = 0
                # starts checking in sequence of locks of str if it matches, adds to count if next block is the same, else it breaks
                for strchain in range(dna_char, len(dnasequence) - (len(each_str) - 1), len(each_str)):
                    dna_block = []
                    for i in range(0, len(each_str), 1):
                        dna_block.append(dnasequence[strchain + i])
                    if ''.join(dna_block) == each_str:
                        count += 1
                    else:
                        if dictofstr[each_str] < count:
                            dictofstr[each_str] = count
                        break
                break
    
    with open(sys.argv[1], 'r') as file:
        dna_names_dict = csv.DictReader(file)
        for name in dna_names_dict:
            match = 0
            for dna_str in strlist:
                if dictofstr[dna_str] == int(name[dna_str]):
                    match +=1
            if match == len(strlist):
                print(name['name'])
                quit()
        print('No Match')
0

Nevermind, it turns out the problems was extremely simple. Near the end where I'm adding the count I placed the break wrong. Solution:

else:
     if dictofstr[each_str] < count:
         dictofstr[each_str] = count
         break
     else:
         break

also, no break underneath, just this snippet.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .