Created
September 30, 2014 23:24
-
-
Save luizirber/9cbe3a21c594a58bae16 to your computer and use it in GitHub Desktop.
Empty list and appending, or list(convert_str)?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"metadata": { | |
"name": "", | |
"signature": "sha256:ba6882fefcb6a29688dda6b637d776a9e5ca4746ecd068494d99acdf615fcd25" | |
}, | |
"nbformat": 3, | |
"nbformat_minor": 0, | |
"worksheets": [ | |
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"def to_rna_string(convert_str):\n", | |
"\n", | |
" # Dict of values that require replacing\n", | |
" replaceValues = {'G': 'C', 'C': 'G', 'T': 'A', 'A': 'U'}\n", | |
"\n", | |
" # Convert input string to list of characters\n", | |
" newStr = list(convert_str)\n", | |
"\n", | |
" # Iterate through list of char and populate replace list\n", | |
" for i in range(0,len(convert_str)):\n", | |
" newStr[i] = replaceValues[convert_str[i]]\n", | |
"\n", | |
" # Return new list as string\n", | |
" return \"\".join(newStr)\n", | |
" \n", | |
"def to_rna_list(convert_str):\n", | |
"\n", | |
" # Dict of values that require replacing\n", | |
" replaceValues = {'G': 'C', 'C': 'G', 'T': 'A', 'A': 'U'}\n", | |
"\n", | |
" # Convert input string to list of characters\n", | |
" newStr = []\n", | |
" \n", | |
" # Iterate through list of char and populate replace list\n", | |
" for i in range(0,len(convert_str)):\n", | |
" newStr.append(replaceValues[convert_str[i]])\n", | |
"\n", | |
" # Return new list as string\n", | |
" return \"\".join(newStr)" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [], | |
"prompt_number": 1 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"import random\n", | |
"huge = \"\".join(random.choice('ACGT') for i in range(10000000))" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [], | |
"prompt_number": 18 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"%timeit -n 10 to_rna_list(huge)" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
"10 loops, best of 3: 2.32 s per loop\n" | |
] | |
} | |
], | |
"prompt_number": 19 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"%timeit -n 10 to_rna_string(huge)" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
"10 loops, best of 3: 1.86 s per loop\n" | |
] | |
} | |
], | |
"prompt_number": 20 | |
} | |
], | |
"metadata": {} | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment