Counting Repeated Str In Dna Pset6 Cs50
Currently working on CS50. I tried to count STR in file DNA Sequences but it always overcount. I mean, for example: how much 'AGATC' in file DNA repeat consecutively. This code is
Solution 1:
The for loop is wrong, it will keep counting the sequences even if they are already found earlier in the loop. I think you want to instead loop over the str_sequences
.
Something like:
seq_list = []
for STR in str_sequences:
groups = re.findall(rf'(?:{STR})+', dna)
iflen(groups) == 0:
seq_list.append('0')
else:
seq_list.append(str(max(map(lambda x: len(x)//len(STR), groups))))
print(seq_list)
Also, there are many posts on this problem. Maybe, you can examine some of them to finish your program.
Post a Comment for "Counting Repeated Str In Dna Pset6 Cs50"