Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
hub-courses
python_one_week_4_biologists_solutions
Commits
1a976522
Commit
1a976522
authored
Sep 08, 2014
by
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
Changes
1
Hide whitespace changes
Inline
Side-by-side
source/Collection_Data_Types.rst
View file @
1a976522
...
...
@@ -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
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment