      "            string[new_length - 2] = '%'\n",
      "            new_length -= 3\n",
      "        else:\n",
      "            string[new_length] = string[i]\n",
      "            new_length -= 1\n",
      "\n",
      "run_tests(encode_spaces)"
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {},
 
</s> remove     "            string[new_length - 1] = '2'\n",
    "            string[new_length - 2] = '%'\n",
 </s> add     "            string[new_length-1] = '2'\n",
    "            string[new_length-2] = '%'\n", </s> remove   {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "from nose.tools import assert_equal\n",
    "\n",
    "class Test(object):\n",
    "    def test_replace_char(self, func):\n",
    "        str0 = None\n",
    "        str1 = bytearray(' ||')\n",
    "        str2 = bytearray(' foo bar ||||||')\n",
    "        str3 = bytearray('foo')\n",
    "        func(str0, 0)\n",
    "        func(str1, 1)\n",
    "        func(str2, 9)\n",
    "        func(str3, 3)\n",
    "        assert_equal(str0, None)\n",
    "        assert_equal(str1, '%20')\n",
    "        assert_equal(str2, '%20foo%20bar%20')\n",
    "        assert_equal(str3, 'foo')\n",
    "\n",
    "def run_tests(func):\n",
    "    test = Test()\n",
    "    test.test_replace_char(func)"
   ]
  },
 </s> add  </s> remove     "* [Pythonic-Code: Not In-Place](#Pythonic-Code:-Not-In-Place)"
 </s> add     "* [Pythonic-Code: Not In-Place](#Pythonic-Code:-Not-In-Place)\n",
    "* [Unit Test](#Unit-Test)" </s> remove     "* Is the string ASCII (extended)?  Or Unicode?\n",
    "    * ASCII extended, which is 256 characters\n",
 </s> add     "*Problem statements are sometimes intentionally ambiguous.  Asking clarifying questions, identifying constraints, and stating assumptions help to ensure you code the intended solution.*\n",
    "\n",
    "* Can I assume the string is ASCII?\n",
    "    * Yes\n",
    "    * Note: Unicode strings could require special handling depending on your language\n", </s> remove    "execution_count": null,
 </s> add    "execution_count": 2,
    "            new_length -= 1"
      "            string[new_length - 2] = '%'\n",
      "            new_length -= 3\n",
      "        else:\n",
      "            string[new_length] = string[i]\n",
    "            new_length -= 1"
    "            new_length -= 1"
    "            new_length -= 1"
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {},
keep keep keep keep replace replace replace keep keep keep keep keep
 Reworked notebook: Added more detail to clarifying questions and test cases.  Reworked algorithm discussion, code, and unit test. 
arrays-strings/replace_char.ipynb