Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 116af68

Browse filesBrowse files
committed
Add enumerate
1 parent 1198ed7 commit 116af68
Copy full SHA for 116af68

File tree

Expand file treeCollapse file tree

1 file changed

+71
-5
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+71
-5
lines changed
Open diff view settings
Collapse file

‎tutorial.ipynb‎

Copy file name to clipboardExpand all lines: tutorial.ipynb
+71-5Lines changed: 71 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@
2626
"#### 4) [Sets](#ch4)\n",
2727
"#### 5) [Decorators](#ch5)\n",
2828
"#### 6) [Threading](#ch6)\n",
29-
"#### 7) [`__slot__` ](#ch7)\n",
30-
"#### 8) [Collections ](#ch8)"
29+
"#### 7) [`__slot__`](#ch7)\n",
30+
"#### 8) [Collections](#ch8)\n",
31+
"#### 9) [Enumerate](#ch9)"
3132
]
3233
},
3334
{
@@ -2325,12 +2326,77 @@
23252326
"And thats all. Don't miss out [Python Collection](https://docs.python.org/3/library/collections.html) documentation."
23262327
]
23272328
},
2329+
{
2330+
"cell_type": "markdown",
2331+
"metadata": {},
2332+
"source": [
2333+
"<a id=\"ch9\"></a>\n",
2334+
"## Chapter 9 - Enumerate\n",
2335+
"\n",
2336+
"The `enumerate()` method adds a counter to an iterable and returns it in a form of enumerate object. "
2337+
]
2338+
},
23282339
{
23292340
"cell_type": "code",
2330-
"execution_count": null,
2341+
"execution_count": 8,
23312342
"metadata": {},
2332-
"outputs": [],
2333-
"source": []
2343+
"outputs": [
2344+
{
2345+
"name": "stdout",
2346+
"output_type": "stream",
2347+
"text": [
2348+
"1 Neur\n",
2349+
"2 Schweinsteiger\n",
2350+
"3 Lahm\n",
2351+
"4 Muller\n"
2352+
]
2353+
}
2354+
],
2355+
"source": [
2356+
"my_list = ['Neur', 'Schweinsteiger', 'Lahm', 'Muller']\n",
2357+
"for c, value in enumerate(my_list, 1):\n",
2358+
" print(c, value)"
2359+
]
2360+
},
2361+
{
2362+
"cell_type": "markdown",
2363+
"metadata": {},
2364+
"source": [
2365+
"Note that `(my_list, 1)` indicates the starting index of the enumerated list."
2366+
]
2367+
},
2368+
{
2369+
"cell_type": "markdown",
2370+
"metadata": {},
2371+
"source": [
2372+
"You can also create tuples containing the index and list item using a list. "
2373+
]
2374+
},
2375+
{
2376+
"cell_type": "code",
2377+
"execution_count": 6,
2378+
"metadata": {},
2379+
"outputs": [
2380+
{
2381+
"name": "stdout",
2382+
"output_type": "stream",
2383+
"text": [
2384+
"[(1, 'Neur'), (2, 'Schweinsteiger'), (3, 'Lahm'), (4, 'Muller')]\n"
2385+
]
2386+
}
2387+
],
2388+
"source": [
2389+
"my_list = ['Neur', 'Schweinsteiger', 'Lahm', 'Muller']\n",
2390+
"counter_list = list(enumerate(my_list, 1))\n",
2391+
"print(counter_list)"
2392+
]
2393+
},
2394+
{
2395+
"cell_type": "markdown",
2396+
"metadata": {},
2397+
"source": [
2398+
"That's it for today!"
2399+
]
23342400
}
23352401
],
23362402
"metadata": {

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.