      "collapsed": false
     },
     "outputs": [],
     "source": [
      "def compress_string(string):\n",
      "    # TODO: Implement me\n",
      "    pass"
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {},
 
</s> remove     "def compress_string(string):\n",
    "    if string is None or len(string) == 0:\n",
    "        return string\n",
    "    result = ''\n",
    "    prev_char = string[0]\n",
    "    count = 0\n",
    "    for char in string:\n",
    "        if char == prev_char:\n",
    "            count += 1\n",
    "        else:\n",
    "            result += prev_char + (str(count) if count > 1 else '')\n",
    "            prev_char = char\n",
    "            count = 1\n",
    "    result += prev_char + (str(count) if count > 1 else '')\n",
    "    return result if len(result) < len(string) else string"
 </s> add     "class CompressString(object):\n",
    "\n",
    "    def compress(self, string):\n",
    "        if string is None or len(string) == 0:\n",
    "            return string\n",
    "        result = ''\n",
    "        prev_char = string[0]\n",
    "        count = 0\n",
    "        for char in string:\n",
    "            if char == prev_char:\n",
    "                count += 1\n",
    "            else:\n",
    "                result += prev_char + (str(count) if count > 1 else '')\n",
    "                prev_char = char\n",
    "                count = 1\n",
    "        result += prev_char + (str(count) if count > 1 else '')\n",
    "        return result if len(result) < len(string) else string" </s> remove     "    test.test_compress(compress_string)\n",
 </s> add     "    compress_string = CompressString()\n",
    "    test.test_compress(compress_string.compress)\n", </s> remove     "    test.test_compress(compress_string)\n",
 </s> add     "    compress_string = CompressString()\n",
    "    test.test_compress(compress_string.compress)\n", </s> remove     "        assert_equal(func('AAABCCDDDD'), 'A3BC2D4')\n",
 </s> add     "        assert_equal(func('AAABCCDDDDE'), 'A3BC2D4E')\n", </s> remove     test.test_compress(compress_string)
 </s> add     compress_string = CompressString()
    test.test_compress(compress_string.compress)
    "class CompressString(object):\n",
    "\n",
    "    def compress(self, string):\n",
    "        # TODO: Implement me\n",
    "        pass"
      "collapsed": false
     },
     "outputs": [],
     "source": [
    "class CompressString(object):\n",
    "\n",
    "    def compress(self, string):\n",
    "        # TODO: Implement me\n",
    "        pass"
    "class CompressString(object):\n",
    "\n",
    "    def compress(self, string):\n",
    "        # TODO: Implement me\n",
    "        pass"
    "class CompressString(object):\n",
    "\n",
    "    def compress(self, string):\n",
    "        # TODO: Implement me\n",
    "        pass"
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {},
keep keep keep keep replace replace replace keep keep keep keep keep
 Move string compress to a class, update test 
arrays_strings/compress/compress_challenge.ipynb