|
140 | 140 | },
|
141 | 141 | {
|
142 | 142 | "cell_type": "code",
|
143 |
| - "execution_count": 4, |
| 143 | + "execution_count": 1, |
144 | 144 | "metadata": {
|
145 | 145 | "cell_style": "split",
|
146 | 146 | "slideshow": {
|
|
160 | 160 | ],
|
161 | 161 | "source": [
|
162 | 162 | "a = [12, 32, 4, 39, 24]\n",
|
163 |
| - "print('a[-1] =', a[-1])\n", |
| 163 | + "print('a[-1] =', a[-1]) # a[len(a) - 1]\n", |
164 | 164 | "print('a[2] =', a[2])\n",
|
165 |
| - "print('a[-2] =', a[-2])" |
| 165 | + "print('a[-2] =', a[-2]) # a[len(a) - 2]" |
166 | 166 | ]
|
167 | 167 | },
|
168 | 168 | {
|
|
318 | 318 | " print(a[i])"
|
319 | 319 | ]
|
320 | 320 | },
|
| 321 | + { |
| 322 | + "cell_type": "markdown", |
| 323 | + "metadata": { |
| 324 | + "slideshow": { |
| 325 | + "slide_type": "subslide" |
| 326 | + } |
| 327 | + }, |
| 328 | + "source": [ |
| 329 | + "### Traversing a list in a Pythonic way " |
| 330 | + ] |
| 331 | + }, |
321 | 332 | {
|
322 | 333 | "cell_type": "code",
|
323 | 334 | "execution_count": 7,
|
|
340 | 351 | }
|
341 | 352 | ],
|
342 | 353 | "source": [
|
343 |
| - "# Traversing a list in a Pythonic way \n", |
344 | 354 | "for value in a:\n",
|
345 | 355 | " print(value)"
|
346 | 356 | ]
|
|
364 | 374 | }
|
365 | 375 | },
|
366 | 376 | "source": [
|
367 |
| - "#### append will add an element to the end of the list" |
| 377 | + "#### `append` will add an element to the end of the list" |
368 | 378 | ]
|
369 | 379 | },
|
370 | 380 | {
|
|
548 | 558 | }
|
549 | 559 | },
|
550 | 560 | "source": [
|
551 |
| - "#### insert will insert an element at a particular index in the list" |
| 561 | + "#### insert will insert an element at a particular index in the list\n", |
| 562 | + "```py\n", |
| 563 | + "list.insert(index, object)\n", |
| 564 | + "```" |
552 | 565 | ]
|
553 | 566 | },
|
554 | 567 | {
|
|
739 | 752 | }
|
740 | 753 | },
|
741 | 754 | "source": [
|
742 |
| - "### Sort a list" |
| 755 | + "### Sort a list\n", |
| 756 | + "The built-in sort function uses an algorithm known as [Tim Sort](https://en.wikipedia.org/wiki/Timsort)." |
743 | 757 | ]
|
744 | 758 | },
|
745 | 759 | {
|
|
972 | 986 | "```py\n",
|
973 | 987 | "list.remove(value) # removes value from the list\n",
|
974 | 988 | "removed_value = list.pop(index) # removes value at index and returns it\n",
|
| 989 | + "last_value = list.pop() # removes the last value and returns it\n", |
| 990 | + "del list[index] # deletes value from list at index\n", |
975 | 991 | "```"
|
976 | 992 | ]
|
977 | 993 | },
|
|
1086 | 1102 | "## tuple\n",
|
1087 | 1103 | "- A list of comma separated values enclosed within parentheses.\n",
|
1088 | 1104 | "- heterogeneous (it can have values of any type)\n",
|
1089 |
| - "- immutable" |
| 1105 | + "- immutable\n", |
| 1106 | + "- supports negative indexing" |
1090 | 1107 | ]
|
1091 | 1108 | },
|
1092 | 1109 | {
|
|
1582 | 1599 | }
|
1583 | 1600 | },
|
1584 | 1601 | "source": [
|
1585 |
| - "### Count number of a particular substring" |
| 1602 | + "### Count number of occurrences of a particular substring" |
1586 | 1603 | ]
|
1587 | 1604 | },
|
1588 | 1605 | {
|
|
1807 | 1824 | "***"
|
1808 | 1825 | ]
|
1809 | 1826 | },
|
| 1827 | + { |
| 1828 | + "cell_type": "markdown", |
| 1829 | + "metadata": { |
| 1830 | + "slideshow": { |
| 1831 | + "slide_type": "slide" |
| 1832 | + } |
| 1833 | + }, |
| 1834 | + "source": [ |
| 1835 | + "### A few extras" |
| 1836 | + ] |
| 1837 | + }, |
| 1838 | + { |
| 1839 | + "cell_type": "code", |
| 1840 | + "execution_count": 5, |
| 1841 | + "metadata": { |
| 1842 | + "slideshow": { |
| 1843 | + "slide_type": "fragment" |
| 1844 | + } |
| 1845 | + }, |
| 1846 | + "outputs": [ |
| 1847 | + { |
| 1848 | + "name": "stdout", |
| 1849 | + "output_type": "stream", |
| 1850 | + "text": [ |
| 1851 | + "C\n", |
| 1852 | + "88\n" |
| 1853 | + ] |
| 1854 | + } |
| 1855 | + ], |
| 1856 | + "source": [ |
| 1857 | + "ascii_value = 67\n", |
| 1858 | + "character = chr(ascii_value)\n", |
| 1859 | + "print(character)\n", |
| 1860 | + "\n", |
| 1861 | + "character = 'X'\n", |
| 1862 | + "ascii_value = ord(character)\n", |
| 1863 | + "print(ascii_value)" |
| 1864 | + ] |
| 1865 | + }, |
| 1866 | + { |
| 1867 | + "cell_type": "markdown", |
| 1868 | + "metadata": { |
| 1869 | + "slideshow": { |
| 1870 | + "slide_type": "skip" |
| 1871 | + } |
| 1872 | + }, |
| 1873 | + "source": [ |
| 1874 | + "***" |
| 1875 | + ] |
| 1876 | + }, |
1810 | 1877 | {
|
1811 | 1878 | "cell_type": "markdown",
|
1812 | 1879 | "metadata": {
|
|
0 commit comments