From dd4097accbad9503bfc51ad608efd8dab4ad68b9 Mon Sep 17 00:00:00 2001 From: Ilona Budapesti Date: Thu, 28 Jun 2018 09:09:43 +0100 Subject: [PATCH] add str.maketrans() solution --- toy-problems/toy-problem-003.ipynb | 47 ++++++++++++++++++++++++++++-- 1 file changed, 45 insertions(+), 2 deletions(-) diff --git a/toy-problems/toy-problem-003.ipynb b/toy-problems/toy-problem-003.ipynb index 49605cb2..74958280 100644 --- a/toy-problems/toy-problem-003.ipynb +++ b/toy-problems/toy-problem-003.ipynb @@ -278,7 +278,7 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": 3, "metadata": { "collapsed": false }, @@ -296,7 +296,7 @@ "\"i hope you didnt translate it by hand. thats what computers are for. doing it in by hand is inefficient and that's why this text is so long. using string.maketrans() is recommended. now apply on the url.\"" ] }, - "execution_count": 17, + "execution_count": 3, "metadata": {}, "output_type": "execute_result" } @@ -369,6 +369,49 @@ "\n" ] }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "text/plain": [ + "\"i hope you didnt translate it by hand. thats what computers are for. doing it in by hand is inefficient and that's why this text is so long. using string.maketrans() is recommended. now apply on the url.\"" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# solution with a built-in function str.maketrans()\n", + "\n", + "table = str.maketrans(\"abcdefghijklmnopqrstuvwxyz\", \"cdefghijklmnopqrstuvwxyzab\")\n", + "raw.translate(table)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [] + }, { "cell_type": "code", "execution_count": null,