Commit 1a976522 authored by Bertrand  NÉRON's avatar Bertrand NÉRON
Browse files

fix solution for kmer

the range is not len(s) -3 but -2 as range exclude the end value
parent 21f50a94
......@@ -272,7 +272,10 @@ solution ::
s = s.replace('\n', '')
kmers = {}
for i in range(len(s) - 3):
# range exclude the last value range(3) -> 0, 1 ,2
# so we nned to go to len(s) minus trimer + 1 to include the
# last base
for i in range(len(s) - 3 +1):
kmer = s[i:i+3]
kmers[kmer] = kmers.get(kmer, 0) + 1
......@@ -285,7 +288,7 @@ we can use also a defaultdict: ::
s = s.replace('\n', '')
kmers = collection.defaultdict(int)
for i in range(len(s) - 3):
for i in range(len(s) - 2):
kmer = s[i:i+3]
kmers[kmer] += 1
......@@ -384,4 +387,4 @@ to create apes we should write: ::
apes = copy.deepcopy(mammals[1])
deepcopy not only copy the list but make also a copy of each items of list recursively.
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment