Added enumerate snippet.

This commit is contained in:
Donne Martin 2015-01-25 12:55:43 -05:00
parent 86a1463df3
commit 32f4daf609

View File

@ -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": {}