mirror of
https://github.com/donnemartin/interactive-coding-challenges
synced 2026-01-09 10:58:02 +00:00
Fix #13, PEP8-ify notebooks.
This commit is contained in:
@@ -100,7 +100,7 @@
|
||||
"def compress_string(string):\n",
|
||||
" if string is None or len(string) == 0:\n",
|
||||
" return string\n",
|
||||
" \n",
|
||||
"\n",
|
||||
" # Calculate the size of the compressed string\n",
|
||||
" size = 0\n",
|
||||
" last_char = string[0]\n",
|
||||
@@ -109,8 +109,8 @@
|
||||
" size += 2\n",
|
||||
" last_char = char\n",
|
||||
" size += 2\n",
|
||||
" \n",
|
||||
" # If the compressed string size is greater than \n",
|
||||
"\n",
|
||||
" # If the compressed string size is greater than\n",
|
||||
" # or equal to string size, return original string\n",
|
||||
" if size >= len(string):\n",
|
||||
" return string\n",
|
||||
@@ -129,7 +129,7 @@
|
||||
" last_char = char\n",
|
||||
" compressed_string.append(last_char)\n",
|
||||
" compressed_string.append(str(count))\n",
|
||||
" \n",
|
||||
"\n",
|
||||
" # Convert the characters in the list to a string\n",
|
||||
" return \"\".join(compressed_string)"
|
||||
]
|
||||
@@ -162,7 +162,7 @@
|
||||
"\n",
|
||||
"\n",
|
||||
"class TestCompress(object):\n",
|
||||
" \n",
|
||||
"\n",
|
||||
" def test_compress(self, func):\n",
|
||||
" assert_equal(func(None), None)\n",
|
||||
" assert_equal(func(''), '')\n",
|
||||
@@ -170,10 +170,12 @@
|
||||
" assert_equal(func('AAABCCDDDD'), 'A3B1C2D4')\n",
|
||||
" print('Success: test_compress')\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"def main():\n",
|
||||
" test = TestCompress()\n",
|
||||
" test.test_compress(compress_string)\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"if __name__ == '__main__':\n",
|
||||
" main()"
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user