I'm trying to record the number of repetitions of each str in the sequence. I created a dictionary as below and another empty dict because i couldn't update a dict while iterating through it. But for some reason my value variable always returns 0 for every str. Any suggestions?
iterator = {
"AGATC": 0,
"TTTTTTCT": 0,
"AATG": 0,
"TCTAG": 0,
"GATA": 0,
"TATC": 0,
"GAAA": 0,
"TCTG": 0
}
record = {
}
for x in iterator:
value = 0
for i in range(0, len(sequence)):
if sequence[i:len(x)] == x:
value += 1
elif sequence[i:len(x)] != x:
value = 0
record.update( {x : value} ) # wordFreqDic.update( {'before' : 23} )
print(record)
This is how it prints :
~/pset6/dna/ $ python dna.py databases/large.csv sequences/1.txt
{'AGATC': 0, 'TTTTTTCT': 0, 'AATG': 0, 'TCTAG': 0, 'GATA': 0, 'TATC': 0, 'GAAA': 0, 'TCTG': 0}