|
4 | 4 | "cell_type": "markdown", |
5 | 5 | "metadata": {}, |
6 | 6 | "source": [ |
7 | | - "# Module 2 - Python Fundamentals\n", |
| 7 | + "# Python Fundamentals Module 2: Lists (P2M2)\n", |
8 | 8 | "## Sequence: Lists \n", |
9 | 9 | "- **List Creation**\n", |
10 | 10 | "- **List Access**\n", |
|
29 | 29 | "# \n", |
30 | 30 | "<font size=\"6\" color=\"#00A0B2\" face=\"verdana\"> <B>Concepts</B></font>\n", |
31 | 31 | "## Creating Lists\n", |
32 | | - "[]( http://edxinteractivepage.blob.core.windows.net/edxpages/f7cff1a7-5601-48a1-95a6-fd1fdfabd20e.html?details=[{\"src\":\"http://jupyternootbookwams.streaming.mediaservices.windows.net/933c4e57-93ae-4660-8725-6eff3987dd1c/Unit2_Section2.1a-Creating_Lists.ism/manifest\",\"type\":\"application/vnd.ms-sstr+xml\"}],[{\"src\":\"http://jupyternootbookwams.streaming.mediaservices.windows.net/933c4e57-93ae-4660-8725-6eff3987dd1c/Unit2_Section2.1a-Creating_Lists.vtt\",\"srclang\":\"en\",\"kind\":\"subtitles\",\"label\":\"english\"}])\n", |
| 32 | + "[]( https://youtu.be/RA1tMeHWjh0)\n", |
33 | 33 | "A simple lists contains **comma separated** objects enclosed in **square brackets** \n", |
34 | 34 | "```python\n", |
35 | 35 | "empty_list = [ ]\n", |
|
144 | 144 | "# \n", |
145 | 145 | "<font size=\"6\" color=\"#00A0B2\" face=\"verdana\"> <B>Concepts</B></font>\n", |
146 | 146 | "## List Access \n", |
147 | | - "[]( http://edxinteractivepage.blob.core.windows.net/edxpages/f7cff1a7-5601-48a1-95a6-fd1fdfabd20e.html?details=[{\"src\":\"http://jupyternootbookwams.streaming.mediaservices.windows.net/efc23682-3b15-4c73-afe0-77067fac2769/Unit2_Section2.1b-Accessing_Lists.ism/manifest\",\"type\":\"application/vnd.ms-sstr+xml\"}],[{\"src\":\"http://jupyternootbookwams.streaming.mediaservices.windows.net/efc23682-3b15-4c73-afe0-77067fac2769/Unit2_Section2.1b-Accessing_Lists.vtt\",\"srclang\":\"en\",\"kind\":\"subtitles\",\"label\":\"english\"}])\n", |
148 | 147 | "### Counting like a computer\n", |
149 | 148 | "#### To access a list we need to count like a computer, and that means starting with zero (0)\n", |
150 | 149 | "Lists give an **index** number to each list item\n", |
|
165 | 164 | "\n", |
166 | 165 | "<font size=\"4\" color=\"#00A0B2\" face=\"verdana\"> <B>Examples</B></font>\n", |
167 | 166 | "\n", |
168 | | - "|run previous examples before running the examples below|\n", |
| 167 | + "|run previous examples before running the examples below Why? Because running them puts their results in memory, available to the code below to use to do further calculations and work |\n", |
169 | 168 | "|-----------------------------------------------------------|\n" |
170 | 169 | ] |
171 | 170 | }, |
|
298 | 297 | "# \n", |
299 | 298 | "<font size=\"6\" color=\"#00A0B2\" face=\"verdana\"> <B>Concepts</B></font>\n", |
300 | 299 | "## Appending to Lists\n", |
301 | | - "[]( http://edxinteractivepage.blob.core.windows.net/edxpages/f7cff1a7-5601-48a1-95a6-fd1fdfabd20e.html?details=[{\"src\":\"http://jupyternootbookwams.streaming.mediaservices.windows.net/121939c6-f81e-4787-a7a9-15ab15c69168/Unit2_Section2.2a-Appending_to_Lists.ism/manifest\",\"type\":\"application/vnd.ms-sstr+xml\"}],[{\"src\":\"http://jupyternootbookwams.streaming.mediaservices.windows.net/121939c6-f81e-4787-a7a9-15ab15c69168/Unit2_Section2.2a-Appending_to_Lists.vtt\",\"srclang\":\"en\",\"kind\":\"subtitles\",\"label\":\"english\"}])\n", |
302 | 300 | "**`.append()`** method adds an item to the end of a list \n", |
303 | 301 | "```python\n", |
304 | 302 | "party_list.append(\"Alton\")\n", |
|
411 | 409 | "\n", |
412 | 410 | "# [ ] print the list\n", |
413 | 411 | "\n", |
414 | | - "\n", |
415 | 412 | "# [ ] append an item to the list and print the list\n", |
416 | 413 | " \n" |
417 | 414 | ] |
|
460 | 457 | "metadata": {}, |
461 | 458 | "outputs": [], |
462 | 459 | "source": [ |
463 | | - "# [ ] complete the Birthday Survey task above\n", |
464 | | - "\n" |
| 460 | + "# [ ] complete the Birthday Survey task above\n" |
465 | 461 | ] |
466 | 462 | }, |
467 | 463 | { |
|
514 | 510 | "# \n", |
515 | 511 | "<font size=\"6\" color=\"#00A0B2\" face=\"verdana\"> <B>Concepts</B></font>\n", |
516 | 512 | "## Insert a new value for an index\n", |
517 | | - "[]( http://edxinteractivepage.blob.core.windows.net/edxpages/f7cff1a7-5601-48a1-95a6-fd1fdfabd20e.html?details=[{\"src\":\"http://jupyternootbookwams.streaming.mediaservices.windows.net/219b35cf-03b5-4b57-8fbc-f5864281312d/Unit2_Section2.3a-Overwriting_an_Index.ism/manifest\",\"type\":\"application/vnd.ms-sstr+xml\"}],[{\"src\":\"http://jupyternootbookwams.streaming.mediaservices.windows.net/219b35cf-03b5-4b57-8fbc-f5864281312d/Unit2_Section2.3a-Overwriting_an_Index.vtt\",\"srclang\":\"en\",\"kind\":\"subtitles\",\"label\":\"english\"}])\n", |
518 | 513 | "### overwrite a specific index in a list\n", |
519 | 514 | "```python\n", |
520 | 515 | "party_list[2] = \"Tobias\"\n", |
|
652 | 647 | "metadata": {}, |
653 | 648 | "outputs": [], |
654 | 649 | "source": [ |
655 | | - "# [ ] create challenge function\n", |
656 | | - "\n", |
657 | | - "\n" |
| 650 | + "# [ ] create challenge function\n" |
658 | 651 | ] |
659 | 652 | }, |
660 | 653 | { |
|
692 | 685 | "# \n", |
693 | 686 | "<font size=\"6\" color=\"#00A0B2\" face=\"verdana\"> <B>Concepts</B></font>\n", |
694 | 687 | "## Insert items into a list\n", |
695 | | - "[]( http://edxinteractivepage.blob.core.windows.net/edxpages/f7cff1a7-5601-48a1-95a6-fd1fdfabd20e.html?details=[{\"src\":\"http://jupyternootbookwams.streaming.mediaservices.windows.net/659b9cd2-1e84-4ead-8a69-015c737577cd/Unit2_Section2.3b-Inserting_Items_into_Lists.ism/manifest\",\"type\":\"application/vnd.ms-sstr+xml\"}],[{\"src\":\"http://jupyternootbookwams.streaming.mediaservices.windows.net/659b9cd2-1e84-4ead-8a69-015c737577cd/Unit2_Section2.3b-Inserting_Items_into_Lists.vtt\",\"srclang\":\"en\",\"kind\":\"subtitles\",\"label\":\"english\"}])\n", |
696 | 688 | "### use `.insert()` to define an index to insert an item\n", |
697 | 689 | "```python\n", |
698 | 690 | "party_list.insert(2,\"Tobias\")\n", |
|
804 | 796 | "# \n", |
805 | 797 | "<font size=\"6\" color=\"#00A0B2\" face=\"verdana\"> <B>Concepts</B></font>\n", |
806 | 798 | "## Delete a specific List index\n", |
807 | | - "[]( http://edxinteractivepage.blob.core.windows.net/edxpages/f7cff1a7-5601-48a1-95a6-fd1fdfabd20e.html?details=[{\"src\":\"http://jupyternootbookwams.streaming.mediaservices.windows.net/072d8761-7811-438e-a77f-72c9634c0f8c/Unit2_Section2.4a-Deleting_Specific_Index.ism/manifest\",\"type\":\"application/vnd.ms-sstr+xml\"}],[{\"src\":\"http://jupyternootbookwams.streaming.mediaservices.windows.net/072d8761-7811-438e-a77f-72c9634c0f8c/Unit2_Section2.4a-Deleting_Specific_Index.vtt\",\"srclang\":\"en\",\"kind\":\"subtitles\",\"label\":\"english\"}])\n", |
808 | 799 | "### `del ` statement \n", |
809 | 800 | "```python\n", |
810 | 801 | "del party_list[2]\n", |
|
925 | 916 | "# \n", |
926 | 917 | "<font size=\"6\" color=\"#00A0B2\" face=\"verdana\"> <B>Concepts</B></font>\n", |
927 | 918 | "## .pop() gets and deletes item in list\n", |
928 | | - "[]( http://edxinteractivepage.blob.core.windows.net/edxpages/f7cff1a7-5601-48a1-95a6-fd1fdfabd20e.html?details=[{\"src\":\"http://jupyternootbookwams.streaming.mediaservices.windows.net/67b83f30-a92c-4d1f-a7a3-ca257dd4db4e/Unit2_Section2.4b-List_Pop_Method.ism/manifest\",\"type\":\"application/vnd.ms-sstr+xml\"}],[{\"src\":\"http://jupyternootbookwams.streaming.mediaservices.windows.net/67b83f30-a92c-4d1f-a7a3-ca257dd4db4e/Unit2_Section2.4b-List_Pop_Method.vtt\",\"srclang\":\"en\",\"kind\":\"subtitles\",\"label\":\"english\"}])\n", |
929 | 919 | "### `.pop()` method default is last item in a list\n", |
930 | 920 | "```python\n", |
931 | 921 | "last_item = party_list.pop()\n", |
|
1024 | 1014 | "# \n", |
1025 | 1015 | "<font size=\"6\" color=\"#00A0B2\" face=\"verdana\"> <B>Concepts</B></font>\n", |
1026 | 1016 | "## an empty list is False\n", |
1027 | | - "[]( http://edxinteractivepage.blob.core.windows.net/edxpages/f7cff1a7-5601-48a1-95a6-fd1fdfabd20e.html?details=[{\"src\":\"http://jupyternootbookwams.streaming.mediaservices.windows.net/20e00a13-a9d2-4a35-b75d-f6533fa15cbd/Unit2_Section2.4c-Empty_List_is_False.ism/manifest\",\"type\":\"application/vnd.ms-sstr+xml\"}],[{\"src\":\"http://jupyternootbookwams.streaming.mediaservices.windows.net/20e00a13-a9d2-4a35-b75d-f6533fa15cbd/Unit2_Section2.4c-Empty_List_is_False.vtt\",\"srclang\":\"en\",\"kind\":\"subtitles\",\"label\":\"english\"}])\n", |
1028 | 1017 | "### in a conditional an empty list will evaluate `False`\n", |
1029 | 1018 | "This allows creating a while loop that runs until a list is empty\n", |
1030 | 1019 | "```python\n", |
|
1111 | 1100 | "# \n", |
1112 | 1101 | "<font size=\"6\" color=\"#00A0B2\" face=\"verdana\"> <B>Concepts</B></font>\n", |
1113 | 1102 | "## Delete a specific object from a list with `.remove()`\n", |
1114 | | - "[]( http://edxinteractivepage.blob.core.windows.net/edxpages/f7cff1a7-5601-48a1-95a6-fd1fdfabd20e.html?details=[{\"src\":\"http://jupyternootbookwams.streaming.mediaservices.windows.net/31fadf38-670c-4ba9-aa68-1934db459c4d/Unit2_Section2.4d-Removing_Object_from_List.ism/manifest\",\"type\":\"application/vnd.ms-sstr+xml\"}],[{\"src\":\"http://jupyternootbookwams.streaming.mediaservices.windows.net/31fadf38-670c-4ba9-aa68-1934db459c4d/Unit2_Section2.4d-Removing_Object_from_List.vtt\",\"srclang\":\"en\",\"kind\":\"subtitles\",\"label\":\"english\"}])\n", |
1115 | 1103 | "### `.remove(object)` removes the 1st item that matches\n", |
1116 | 1104 | "\n", |
1117 | 1105 | "```python\n", |
|
1147 | 1135 | { |
1148 | 1136 | "cell_type": "code", |
1149 | 1137 | "execution_count": null, |
1150 | | - "metadata": {}, |
| 1138 | + "metadata": { |
| 1139 | + "scrolled": true |
| 1140 | + }, |
1151 | 1141 | "outputs": [], |
1152 | 1142 | "source": [ |
1153 | 1143 | "# [ ] review and run example\n", |
|
1205 | 1195 | "cell_type": "markdown", |
1206 | 1196 | "metadata": {}, |
1207 | 1197 | "source": [ |
1208 | | - "[Terms of use](http://go.microsoft.com/fwlink/?LinkID=206977) [Privacy & cookies](https://go.microsoft.com/fwlink/?LinkId=521839) © 2017 Microsoft" |
| 1198 | + "© 2017 Microsoft adapted with permission by Dominic Thomas" |
1209 | 1199 | ] |
1210 | 1200 | } |
1211 | 1201 | ], |
|
0 commit comments