mirror of
https://github.com/donnemartin/interactive-coding-challenges.git
synced 2024-03-22 13:11:13 +08:00
203 lines
4.8 KiB
Python
203 lines
4.8 KiB
Python
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"deletable": true,
|
|
"editable": true
|
|
},
|
|
"source": [
|
|
"This notebook was prepared by [eamanu](http://github.com/eamanu). Source and license info is on [GitHub](https://github.com/donnemartin/interactive-coding-challenges)."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"deletable": true,
|
|
"editable": true
|
|
},
|
|
"source": [
|
|
"# Challenge Notebook"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"deletable": true,
|
|
"editable": true
|
|
},
|
|
"source": [
|
|
"## Problem: Remove specified characters in a string\t\n",
|
|
"\n",
|
|
"* [Constraints](#Constraints)\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": {
|
|
"deletable": true,
|
|
"editable": true
|
|
},
|
|
"source": [
|
|
"## Constraints\n",
|
|
"\n",
|
|
"* Can we assume the string is ASCII?\n",
|
|
" * Yes\n",
|
|
" * Note: Unicode strings could require special handling depending on your language\n",
|
|
"* Can we assume this is case sensitive?\n",
|
|
" * Yes\n",
|
|
"* Can we use additional data structures?\n",
|
|
" * Yes\n",
|
|
"* Can we assume this fits in memory?\n",
|
|
" * Yes"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"deletable": true,
|
|
"editable": true
|
|
},
|
|
"source": [
|
|
"## Test Cases\n",
|
|
"\n",
|
|
"String = 'Python is great'\n",
|
|
"chars -> This is the characters to remove from String\n",
|
|
"\n",
|
|
"* chars = None -> False\n",
|
|
"* chars = '' -> 'Python is great'\n",
|
|
"* chars = 'y' -> 'Pthon is great'\n",
|
|
"* chars = 'tp' -> 'yhon is grea'"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"deletable": true,
|
|
"editable": true
|
|
},
|
|
"source": [
|
|
"## Algorithm\n",
|
|
"\n",
|
|
"Refer to the [Solution Notebook](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/arrays_strings/remove_chars/remove_chars_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": {
|
|
"deletable": true,
|
|
"editable": true
|
|
},
|
|
"source": [
|
|
"## Code"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {
|
|
"collapsed": false,
|
|
"deletable": true,
|
|
"editable": true
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"class RemoveChars(object):\n",
|
|
" def remove_chars(self, string, chars):\n",
|
|
" # TODO: Implement me\n",
|
|
" pass\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"deletable": true,
|
|
"editable": true
|
|
},
|
|
"source": [
|
|
"## Unit Test"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"deletable": true,
|
|
"editable": true
|
|
},
|
|
"source": [
|
|
"**The following unit test is expected to fail until you solve the challenge.**"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {
|
|
"collapsed": false,
|
|
"deletable": true,
|
|
"editable": true
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"# %load test_remove_chars.py\n",
|
|
"from nose.tools import assert_equal\n",
|
|
"\n",
|
|
"\n",
|
|
"class TestRemoveChars(object):\n",
|
|
" def test_remove_chars(self, string, func):\n",
|
|
" assert_equal(func(string, None), False)\n",
|
|
" assert_equal(func(string, ''), 'Python is great')\n",
|
|
" assert_equal(func(string, 'y'), 'Pthon is great')\n",
|
|
" assert_equal(func(string, 'tP'), 'yhon is grea')\n",
|
|
" print('Success: test_remove_chars')\n",
|
|
"\n",
|
|
"\n",
|
|
"def main():\n",
|
|
" test = TestRemoveChars()\n",
|
|
" remove_chars = RemoveChars()\n",
|
|
" string = 'Python is great'\n",
|
|
" test.test_remove_chars(string, remove_chars.remove_chars)\n",
|
|
"if __name__ == '__main__':\n",
|
|
" main()\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"deletable": true,
|
|
"editable": true
|
|
},
|
|
"source": [
|
|
"## Solution Notebook\n",
|
|
"\n",
|
|
"Review the [Solution Notebook](http://nbviewer.ipython.org/github/donnemartin/interactive-coding-challenges/blob/master/arrays_strings/remove_chars/remove_chars_solution.ipynb) for a 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.12"
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 0
|
|
}
|