{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ " This notebook was prepared by Marco Guajardo. For license visit [github](https://github.com/donnemartin/interactive-coding-challenges) \n", "." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Challenge Notebook\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Problem: Given a string of words, return a string with the words in reverse" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "* [Constraits](#Constraint)\n", "* [Test Cases](#Test-Cases)\n", "* [Algorithm](#Algorithm)\n", "* [Code](#Code)\n", "* [Unit Test](#Unit-Test)\n", "* [Solution Notebook](#Solution-Notebook)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Constraints\n", "* Can we assume the string is ASCII?\n", " * Yes\n", "* Is whitespace important?\n", " * no the whitespace does not change\n", "* Is this case sensitive?\n", " * yes\n", "* What if the string is empty?\n", " * return None\n", "* Is the order of words important?\n", " * yes\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Test Cases\n", "* Empty string -> None\n", "* \"the sun is very hot\" -> \"eht nus si yrev toh\"\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Algorithm\n", "* Refer to the [Solution](https://github.com/donnemartin/interactive-coding-challenges/blob/master/arrays_strings/reverse_words/reverse_words_solution.ipynb) if you are stuck and need a hint, the solution notebook's algorithm discussion might be a good place to start." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Code " ] }, { "cell_type": "code", "execution_count": 21, "metadata": { "collapsed": false }, "outputs": [], "source": [ "def reverse_words (S):\n", " #TODO: implement me\n", " pass " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Unit Test\n", " The following unit test is expected to fail until you solve challenge " ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false }, "outputs": [], "source": [ "from nose.tools import assert_equal\n", "\n", "class UnitTest (object):\n", " def testReverseWords(self):\n", " assert_equal(func('the sun is hot'), 'eht nus si toh')\n", " assert_equal(func(''), None)\n", " assert_equal(func('123 456 789'), '321 654 987')\n", " assert_equal(func('magic'), 'cigam')\n", " print('Success: reverse_words')\n", " \n", "def main():\n", " test = UnitTest()\n", " test.testReverseWords()\n", "\n", "if __name__==\"__main__\":\n", " main()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Solution Notebook\n", "* Review the [Solution Notebook](https://github.com/donnemartin/interactive-coding-challenges/blob/master/arrays_strings/reverse_words/reverse_words_solution.ipynb) for discussion on algorithms and code solutions." ] } ], "metadata": { "kernelspec": { "display_name": "Python 2", "language": "python", "name": "python2" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 2 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", "version": "2.7.6" } }, "nbformat": 4, "nbformat_minor": 0 }