From fc1ccf3cde1ec58956091e6a8d1b553923d93cf2 Mon Sep 17 00:00:00 2001 From: rasbt Date: Mon, 16 Jun 2014 07:47:24 -0400 Subject: [PATCH] fix xrange py2 --- ...y_differences_between_python_2_and_3.ipynb | 60 ++++++++++++------- 1 file changed, 37 insertions(+), 23 deletions(-) diff --git a/tutorials/key_differences_between_python_2_and_3.ipynb b/tutorials/key_differences_between_python_2_and_3.ipynb index c940318..f3e2067 100644 --- a/tutorials/key_differences_between_python_2_and_3.ipynb +++ b/tutorials/key_differences_between_python_2_and_3.ipynb @@ -1,7 +1,7 @@ { "metadata": { "name": "", - "signature": "sha256:53ee36d6fcce5f6dbce838e41d83e62fbb143538fe3ca1b0f3cd9b5505e5d786" + "signature": "sha256:1a71ccc70829239143d02cebcb97bec031b45e676ebad340fc04c9bd4a5760bf" }, "nbformat": 3, "nbformat_minor": 0, @@ -349,13 +349,13 @@ "output_type": "stream", "stream": "stdout", "text": [ - "Python 2.7.6\n", + "Python 2.7.7\n", "('a', 'b')\n", "a b\n" ] } ], - "prompt_number": 4 + "prompt_number": 2 }, { "cell_type": "markdown", @@ -739,7 +739,7 @@ "\n", "n = 10000\n", "def test_range(n):\n", - " for i in range(n):\n", + " return for i in range(n):\n", " pass\n", " \n", "def test_xrange(n):\n", @@ -912,32 +912,26 @@ "language": "python", "metadata": {}, "outputs": [], - "prompt_number": 4 + "prompt_number": 3 }, { "cell_type": "code", "collapsed": false, "input": [ "def val_in_range(x, val):\n", - " if val in range(x):\n", - " return True\n", - " else:\n", - " return False" + " return val in range(x)" ], "language": "python", "metadata": {}, "outputs": [], - "prompt_number": 10 + "prompt_number": 4 }, { "cell_type": "code", "collapsed": false, "input": [ "def val_in_xrange(x, val):\n", - " if val in range(x):\n", - " return True\n", - " else:\n", - " return False" + " return val in xrange(x)" ], "language": "python", "metadata": {}, @@ -961,8 +955,8 @@ "output_type": "stream", "stream": "stdout", "text": [ - "Python 3.3.5\n", - "1 loops, best of 3: 751 ms per loop" + "Python 3.4.1\n", + "1 loops, best of 3: 742 ms per loop" ] }, { @@ -970,7 +964,7 @@ "stream": "stdout", "text": [ "\n", - "1000000 loops, best of 3: 1.21 \u00b5s per loop" + "1000000 loops, best of 3: 1.19 \u00b5s per loop" ] }, { @@ -981,7 +975,7 @@ ] } ], - "prompt_number": 11 + "prompt_number": 7 }, { "cell_type": "markdown", @@ -1004,8 +998,12 @@ "print 'Python', python_version()\n", "assert(val_in_xrange(x, x/2.0) == True)\n", "assert(val_in_xrange(x, x/2) == True)\n", + "assert(val_in_range(x, x/2) == True)\n", + "assert(val_in_range(x, x//2) == True)\n", "%timeit val_in_xrange(x, x/2.0)\n", - "%timeit val_in_xrange(x, x/2)" + "%timeit val_in_xrange(x, x/2)\n", + "%timeit val_in_range(x, x/2.0)\n", + "%timeit val_in_range(x, x/2)" ], "language": "python", "metadata": {}, @@ -1015,7 +1013,7 @@ "stream": "stdout", "text": [ "Python 2.7.7\n", - "1 loops, best of 3: 661 ms per loop" + "1 loops, best of 3: 285 ms per loop" ] }, { @@ -1023,7 +1021,23 @@ "stream": "stdout", "text": [ "\n", - "1 loops, best of 3: 564 ms per loop" + "1 loops, best of 3: 179 ms per loop" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "1 loops, best of 3: 658 ms per loop" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "1 loops, best of 3: 556 ms per loop" ] }, { @@ -1070,13 +1084,13 @@ { "metadata": {}, "output_type": "pyout", - "prompt_number": 2, + "prompt_number": 8, "text": [ "" ] } ], - "prompt_number": 2 + "prompt_number": 8 }, { "cell_type": "code",