      "collapsed": false
     },
     "outputs": [],
     "source": [
      "print('Empty input')\n",
      "data = []\n",
      "print(quick_sort(data))\n",
      "print('One element')\n",
      "data = [5]\n",
      "print(quick_sort(data))\n",
      "print('Two or more elements')\n",
      "data = [5, 1, 7, 2, 6, -3, 5, 7, -1]\n",
      "print(quick_sort(data))"
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {},
 
</s> remove     "collapsed": false
 </s> add     "collapsed": true </s> remove     "def quick_sort(arr): \n",
    "     if len(arr) <= 1:\n",
    "          return arr\n",
    "     else:\n",
    "          return qsort([x for x in arr[1:] if x<arr[0]]) + [arr[0]] + qsort([x for x in arr[1:] if x>=arr[0]])"
 </s> add     "from nose.tools import assert_equal\n",
    "\n",
    "class Test(object):\n",
    "    def test_quick_sort(self, func):\n",
    "        print('Empty input')\n",
    "        data = []\n",
    "        func(data)\n",
    "        assert_equal(data, [])\n",
    "\n",
    "        print('One element')\n",
    "        data = [5]\n",
    "        func(data)\n",
    "        assert_equal(data, [5])\n",
    "\n",
    "        print('Two or more elements')\n",
    "        data = [5, 1, 7, 2, 6, -3, 5, 7, -1]\n",
    "        data = func(data)\n",
    "        assert_equal(data, sorted(data))\n",
    "        \n",
    "        print('Success: test_quick_sort\\n')\n",
    "\n",
    "if __name__ == '__main__':\n",
    "    test = Test()\n",
    "    test.test_quick_sort(quick_sort)\n",
    "    test.test_quick_sort(quick_sort_alt)" </s> remove    "execution_count": null,
 </s> add    "execution_count": 1, </s> remove    "execution_count": null,
 </s> add    "execution_count": 2, </s> remove    "outputs": [],
 </s> add    "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Empty input\n",
      "One element\n",
      "Two or more elements\n",
      "Success: test_quick_sort\n",
      "\n",
      "Empty input\n",
      "One element\n",
      "Two or more elements\n",
      "Success: test_quick_sort\n",
      "\n"
     ]
    }
   ],
    "def quick_sort_alt(arr): \n",
    "     if len(arr) <= 1:\n",
    "          return arr\n",
    "     else:\n",
    "          return quick_sort_alt([x for x in arr[1:] if x<arr[0]]) + [arr[0]] + quick_sort_alt([x for x in arr[1:] if x>=arr[0]])"
      "collapsed": false
     },
     "outputs": [],
     "source": [
    "def quick_sort_alt(arr): \n",
    "     if len(arr) <= 1:\n",
    "          return arr\n",
    "     else:\n",
    "          return quick_sort_alt([x for x in arr[1:] if x<arr[0]]) + [arr[0]] + quick_sort_alt([x for x in arr[1:] if x>=arr[0]])"
    "def quick_sort_alt(arr): \n",
    "     if len(arr) <= 1:\n",
    "          return arr\n",
    "     else:\n",
    "          return quick_sort_alt([x for x in arr[1:] if x<arr[0]]) + [arr[0]] + quick_sort_alt([x for x in arr[1:] if x>=arr[0]])"
    "def quick_sort_alt(arr): \n",
    "     if len(arr) <= 1:\n",
    "          return arr\n",
    "     else:\n",
    "          return quick_sort_alt([x for x in arr[1:] if x<arr[0]]) + [arr[0]] + quick_sort_alt([x for x in arr[1:] if x>=arr[0]])"
    "def quick_sort_alt(arr): \n",
    "     if len(arr) <= 1:\n",
    "          return arr\n",
    "     else:\n",
    "          return quick_sort_alt([x for x in arr[1:] if x<arr[0]]) + [arr[0]] + quick_sort_alt([x for x in arr[1:] if x>=arr[0]])"
    "def quick_sort_alt(arr): \n",
    "     if len(arr) <= 1:\n",
    "          return arr\n",
    "     else:\n",
    "          return quick_sort_alt([x for x in arr[1:] if x<arr[0]]) + [arr[0]] + quick_sort_alt([x for x in arr[1:] if x>=arr[0]])"
    "def quick_sort_alt(arr): \n",
    "     if len(arr) <= 1:\n",
    "          return arr\n",
    "     else:\n",
    "          return quick_sort_alt([x for x in arr[1:] if x<arr[0]]) + [arr[0]] + quick_sort_alt([x for x in arr[1:] if x>=arr[0]])"
    "def quick_sort_alt(arr): \n",
    "     if len(arr) <= 1:\n",
    "          return arr\n",
    "     else:\n",
    "          return quick_sort_alt([x for x in arr[1:] if x<arr[0]]) + [arr[0]] + quick_sort_alt([x for x in arr[1:] if x>=arr[0]])"
    "def quick_sort_alt(arr): \n",
    "     if len(arr) <= 1:\n",
    "          return arr\n",
    "     else:\n",
    "          return quick_sort_alt([x for x in arr[1:] if x<arr[0]]) + [arr[0]] + quick_sort_alt([x for x in arr[1:] if x>=arr[0]])"
    "def quick_sort_alt(arr): \n",
    "     if len(arr) <= 1:\n",
    "          return arr\n",
    "     else:\n",
    "          return quick_sort_alt([x for x in arr[1:] if x<arr[0]]) + [arr[0]] + quick_sort_alt([x for x in arr[1:] if x>=arr[0]])"
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {},
keep keep keep keep replace replace replace replace replace replace replace replace replace keep keep keep keep keep
 Reworked notebook: Added more detail to constraints and test cases.  Reworked code and unit test. 
sorting-searching/quick-sort.ipynb