mirror of
https://github.com/donnemartin/interactive-coding-challenges.git
synced 2024-03-22 13:11:13 +08:00
Moved pythonic solution after the initial python solution and prior to the C solution.
This commit is contained in:
parent
7ee5a4da8f
commit
7ec208b0eb
|
@ -17,9 +17,9 @@
|
||||||
"* [Test Cases](#Test-Cases)\n",
|
"* [Test Cases](#Test-Cases)\n",
|
||||||
"* [Algorithm](#Algorithm)\n",
|
"* [Algorithm](#Algorithm)\n",
|
||||||
"* [Code](#Code)\n",
|
"* [Code](#Code)\n",
|
||||||
|
"* [Pythonic-Code](#Pythonic-Code)\n",
|
||||||
"* [C Algorithm](C-Algorithm)\n",
|
"* [C Algorithm](C-Algorithm)\n",
|
||||||
"* [C Code]()\n",
|
"* [C Code]()"
|
||||||
"* [Pythonic-Code](#Pythonic-Code)"
|
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -47,7 +47,7 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 3,
|
"execution_count": null,
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"collapsed": false
|
"collapsed": false
|
||||||
},
|
},
|
||||||
|
@ -92,7 +92,7 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 4,
|
"execution_count": null,
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"collapsed": false
|
"collapsed": false
|
||||||
},
|
},
|
||||||
|
@ -111,6 +111,37 @@
|
||||||
"run_tests(reverse_string)"
|
"run_tests(reverse_string)"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"## Pythonic-Code\n",
|
||||||
|
"\n",
|
||||||
|
"This question has an artificial constraint that prevented the use of the slice operator and the reversed method. For completeness, the solutions for these are provided below."
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"metadata": {
|
||||||
|
"collapsed": false
|
||||||
|
},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"def reverse_string_alt(string):\n",
|
||||||
|
" if string is None:\n",
|
||||||
|
" return None\n",
|
||||||
|
" return string[::-1]\n",
|
||||||
|
"\n",
|
||||||
|
"def reverse_string_alt2(string):\n",
|
||||||
|
" if string is None:\n",
|
||||||
|
" return None \n",
|
||||||
|
" return ''.join(reversed(string))\n",
|
||||||
|
"\n",
|
||||||
|
"run_tests(reverse_string_alt)\n",
|
||||||
|
"run_tests(reverse_string_alt2)"
|
||||||
|
]
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "markdown",
|
"cell_type": "markdown",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
|
@ -189,37 +220,6 @@
|
||||||
" return 0;\n",
|
" return 0;\n",
|
||||||
"}"
|
"}"
|
||||||
]
|
]
|
||||||
},
|
|
||||||
{
|
|
||||||
"cell_type": "markdown",
|
|
||||||
"metadata": {},
|
|
||||||
"source": [
|
|
||||||
"## Pythonic-Code\n",
|
|
||||||
"\n",
|
|
||||||
"This question has an artificial constraint that prevented the use of the slice operator and the reversed method. For completeness, the solutions for these are provided below."
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"cell_type": "code",
|
|
||||||
"execution_count": 7,
|
|
||||||
"metadata": {
|
|
||||||
"collapsed": false
|
|
||||||
},
|
|
||||||
"outputs": [],
|
|
||||||
"source": [
|
|
||||||
"def reverse_string_alt(string):\n",
|
|
||||||
" if string is None:\n",
|
|
||||||
" return None\n",
|
|
||||||
" return string[::-1]\n",
|
|
||||||
"\n",
|
|
||||||
"def reverse_string_alt2(string):\n",
|
|
||||||
" if string is None:\n",
|
|
||||||
" return None \n",
|
|
||||||
" return ''.join(reversed(string))\n",
|
|
||||||
"\n",
|
|
||||||
"run_tests(reverse_string_alt)\n",
|
|
||||||
"run_tests(reverse_string_alt2)"
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"metadata": {
|
"metadata": {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user