From 32f4daf6093184be1a5ac66145297282a2d419fe Mon Sep 17 00:00:00 2001 From: Donne Martin Date: Sun, 25 Jan 2015 12:55:43 -0500 Subject: [PATCH] Added enumerate snippet. --- core/structs.ipynb | 70 +++++++++++++++++++++++++++++++++------------- 1 file changed, 50 insertions(+), 20 deletions(-) diff --git a/core/structs.ipynb b/core/structs.ipynb index 3c24bb4..ca6e085 100644 --- a/core/structs.ipynb +++ b/core/structs.ipynb @@ -1,7 +1,7 @@ { "metadata": { "name": "", - "signature": "sha256:81da7477f866f68f73a55003c5ea2e9a1ebc2c30bc7f6b884fa153c45265f794" + "signature": "sha256:c5099245c74de456735197b7914b9a407b7fd42bc3fd7db0d637d1423436d0e6" }, "nbformat": 3, "nbformat_minor": 0, @@ -338,13 +338,13 @@ { "metadata": {}, "output_type": "pyout", - "prompt_number": 39, + "prompt_number": 12, "text": [ "[1, 2, 3]" ] } ], - "prompt_number": 39 + "prompt_number": 12 }, { "cell_type": "markdown", @@ -1077,13 +1077,13 @@ { "metadata": {}, "output_type": "pyout", - "prompt_number": 51, + "prompt_number": 38, "text": [ "[1, 2, 5, 7, 8, 9, (1, 2), (4, 2)]" ] } ], - "prompt_number": 51 + "prompt_number": 38 }, { "cell_type": "markdown", @@ -1111,13 +1111,51 @@ { "metadata": {}, "output_type": "pyout", - "prompt_number": 53, + "prompt_number": 39, "text": [ "[(1, 2), (1, 2), (4, 2), 1, 5, 2, 9, 9, 7, 8, 1, 5, 2]" ] } ], - "prompt_number": 53 + "prompt_number": 39 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## enumerate" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "enumerate gives you the index of a collection and the value" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "numbers = ['zero', 'one', 'two', 'three']\n", + "for i, number in enumerate(numbers):\n", + " print(i, number)" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "(0, 'zero')\n", + "(1, 'one')\n", + "(2, 'two')\n", + "(3, 'three')\n" + ] + } + ], + "prompt_number": 40 }, { "cell_type": "markdown", @@ -1210,7 +1248,7 @@ ] } ], - "prompt_number": 50 + "prompt_number": 43 }, { "cell_type": "markdown", @@ -1233,13 +1271,13 @@ { "metadata": {}, "output_type": "pyout", - "prompt_number": 47, + "prompt_number": 44, "text": [ "(1, 2, 3)" ] } ], - "prompt_number": 47 + "prompt_number": 44 }, { "cell_type": "code", @@ -1253,21 +1291,13 @@ { "metadata": {}, "output_type": "pyout", - "prompt_number": 48, + "prompt_number": 45, "text": [ "('one', 'two', 'three')" ] } ], - "prompt_number": 48 - }, - { - "cell_type": "code", - "collapsed": false, - "input": [], - "language": "python", - "metadata": {}, - "outputs": [] + "prompt_number": 45 } ], "metadata": {}