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
a61cb0b0
Commit
a61cb0b0
authored
Jul 20, 2014
by
Bertrand NÉRON
Browse files
add alt solution for exercise on kmer
add solution using a defaultdict
parent
de19a22e
Changes
1
Hide whitespace changes
Inline
Side-by-side
source/Collection_Data_Types.rst
View file @
a61cb0b0
...
...
@@ -275,6 +275,16 @@ solution ::
for kmer, occurence in kmers.items():
print kmer, " = ", occurence
we can use also a defaultdict: ::
import collections
s = s.replace('\n', '')
kmers = collection.defaultdict(int)
for i in range(len(s) - 3):
kmer = s[i:i+3]
kmers[kmer] += 1
solution bonus ::
list_of_kmers = kmers.items()
...
...
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