diff --git a/arrays-strings/reverse_string.ipynb b/arrays-strings/reverse_string.ipynb index 927b49e..9cebfe7 100644 --- a/arrays-strings/reverse_string.ipynb +++ b/arrays-strings/reverse_string.ipynb @@ -17,9 +17,9 @@ "* [Test Cases](#Test-Cases)\n", "* [Algorithm](#Algorithm)\n", "* [Code](#Code)\n", + "* [Pythonic-Code](#Pythonic-Code)\n", "* [C Algorithm](C-Algorithm)\n", - "* [C Code]()\n", - "* [Pythonic-Code](#Pythonic-Code)" + "* [C Code]()" ] }, { @@ -47,7 +47,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": null, "metadata": { "collapsed": false }, @@ -92,7 +92,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": null, "metadata": { "collapsed": false }, @@ -111,6 +111,37 @@ "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", "metadata": {}, @@ -189,37 +220,6 @@ " 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": {