|  | 
|  | 1 | +{ | 
|  | 2 | + "cells": [ | 
|  | 3 | + { | 
|  | 4 | + "cell_type": "code", | 
|  | 5 | + "execution_count": 1, | 
|  | 6 | + "metadata": {}, | 
|  | 7 | + "outputs": [ | 
|  | 8 | + { | 
|  | 9 | + "data": { | 
|  | 10 | + "text/plain": [ | 
|  | 11 | + "[1998, 1999, 2000, 2001, 2002]" | 
|  | 12 | + ] | 
|  | 13 | + }, | 
|  | 14 | + "execution_count": 1, | 
|  | 15 | + "metadata": {}, | 
|  | 16 | + "output_type": "execute_result" | 
|  | 17 | + } | 
|  | 18 | + ], | 
|  | 19 | + "source": [ | 
|  | 20 | + "years_list = [res for res in range(1998,2003)]\n", | 
|  | 21 | + "years_list" | 
|  | 22 | + ] | 
|  | 23 | + }, | 
|  | 24 | + { | 
|  | 25 | + "cell_type": "code", | 
|  | 26 | + "execution_count": 3, | 
|  | 27 | + "metadata": {}, | 
|  | 28 | + "outputs": [ | 
|  | 29 | + { | 
|  | 30 | + "data": { | 
|  | 31 | + "text/plain": [ | 
|  | 32 | + "2001" | 
|  | 33 | + ] | 
|  | 34 | + }, | 
|  | 35 | + "execution_count": 3, | 
|  | 36 | + "metadata": {}, | 
|  | 37 | + "output_type": "execute_result" | 
|  | 38 | + } | 
|  | 39 | + ], | 
|  | 40 | + "source": [ | 
|  | 41 | + "years_list[3]" | 
|  | 42 | + ] | 
|  | 43 | + }, | 
|  | 44 | + { | 
|  | 45 | + "cell_type": "code", | 
|  | 46 | + "execution_count": 4, | 
|  | 47 | + "metadata": {}, | 
|  | 48 | + "outputs": [ | 
|  | 49 | + { | 
|  | 50 | + "data": { | 
|  | 51 | + "text/plain": [ | 
|  | 52 | + "2002" | 
|  | 53 | + ] | 
|  | 54 | + }, | 
|  | 55 | + "execution_count": 4, | 
|  | 56 | + "metadata": {}, | 
|  | 57 | + "output_type": "execute_result" | 
|  | 58 | + } | 
|  | 59 | + ], | 
|  | 60 | + "source": [ | 
|  | 61 | + "max(years_list)" | 
|  | 62 | + ] | 
|  | 63 | + }, | 
|  | 64 | + { | 
|  | 65 | + "cell_type": "code", | 
|  | 66 | + "execution_count": 5, | 
|  | 67 | + "metadata": {}, | 
|  | 68 | + "outputs": [], | 
|  | 69 | + "source": [ | 
|  | 70 | + "things = [\"mozzarella\", \"cinderella\", \"salmonella\"]" | 
|  | 71 | + ] | 
|  | 72 | + }, | 
|  | 73 | + { | 
|  | 74 | + "cell_type": "code", | 
|  | 75 | + "execution_count": 10, | 
|  | 76 | + "metadata": {}, | 
|  | 77 | + "outputs": [ | 
|  | 78 | + { | 
|  | 79 | + "name": "stdout", | 
|  | 80 | + "output_type": "stream", | 
|  | 81 | + "text": [ | 
|  | 82 | + "Cinderella\n", | 
|  | 83 | + "Memory location of this transformed element: 1657709639920\n" | 
|  | 84 | + ] | 
|  | 85 | + } | 
|  | 86 | + ], | 
|  | 87 | + "source": [ | 
|  | 88 | + "## this value is stored in different location because of which original list is not affected.\n", | 
|  | 89 | + "print(things[1].capitalize())\n", | 
|  | 90 | + "print(\"Memory location of this transformed element: \",id(things[1].capitalize()))" | 
|  | 91 | + ] | 
|  | 92 | + }, | 
|  | 93 | + { | 
|  | 94 | + "cell_type": "code", | 
|  | 95 | + "execution_count": 11, | 
|  | 96 | + "metadata": {}, | 
|  | 97 | + "outputs": [ | 
|  | 98 | + { | 
|  | 99 | + "name": "stdout", | 
|  | 100 | + "output_type": "stream", | 
|  | 101 | + "text": [ | 
|  | 102 | + "['mozzarella', 'cinderella', 'salmonella']\n", | 
|  | 103 | + "Memory location of original list: 1657677592128\n" | 
|  | 104 | + ] | 
|  | 105 | + } | 
|  | 106 | + ], | 
|  | 107 | + "source": [ | 
|  | 108 | + "## No it didnt change element in list.It stores the transforemd element in other memory location hence proved\n", | 
|  | 109 | + "print(things)\n", | 
|  | 110 | + "print(\"Memory location of original list: \",id(things))" | 
|  | 111 | + ] | 
|  | 112 | + }, | 
|  | 113 | + { | 
|  | 114 | + "cell_type": "code", | 
|  | 115 | + "execution_count": 12, | 
|  | 116 | + "metadata": {}, | 
|  | 117 | + "outputs": [], | 
|  | 118 | + "source": [ | 
|  | 119 | + "surprise_list = [\"Groucho\",\"Chico\",\"Harpo\"] " | 
|  | 120 | + ] | 
|  | 121 | + }, | 
|  | 122 | + { | 
|  | 123 | + "cell_type": "code", | 
|  | 124 | + "execution_count": 16, | 
|  | 125 | + "metadata": {}, | 
|  | 126 | + "outputs": [ | 
|  | 127 | + { | 
|  | 128 | + "name": "stdout", | 
|  | 129 | + "output_type": "stream", | 
|  | 130 | + "text": [ | 
|  | 131 | + "harpo\n", | 
|  | 132 | + "Reversed List: ['Harpo', 'Chico', 'Groucho']\n" | 
|  | 133 | + ] | 
|  | 134 | + }, | 
|  | 135 | + { | 
|  | 136 | + "data": { | 
|  | 137 | + "text/plain": [ | 
|  | 138 | + "['Groucho', 'Chico', 'Harpo']" | 
|  | 139 | + ] | 
|  | 140 | + }, | 
|  | 141 | + "execution_count": 16, | 
|  | 142 | + "metadata": {}, | 
|  | 143 | + "output_type": "execute_result" | 
|  | 144 | + } | 
|  | 145 | + ], | 
|  | 146 | + "source": [ | 
|  | 147 | + "print(surprise_list[2].lower())\n", | 
|  | 148 | + "reverse_list = surprise_list[::-1]\n", | 
|  | 149 | + "print(\"Reversed List: \",reverse_list)\n", | 
|  | 150 | + "[c.capitalize() for c in surprise_list]" | 
|  | 151 | + ] | 
|  | 152 | + }, | 
|  | 153 | + { | 
|  | 154 | + "cell_type": "code", | 
|  | 155 | + "execution_count": 19, | 
|  | 156 | + "metadata": {}, | 
|  | 157 | + "outputs": [ | 
|  | 158 | + { | 
|  | 159 | + "data": { | 
|  | 160 | + "text/plain": [ | 
|  | 161 | + "dict" | 
|  | 162 | + ] | 
|  | 163 | + }, | 
|  | 164 | + "execution_count": 19, | 
|  | 165 | + "metadata": {}, | 
|  | 166 | + "output_type": "execute_result" | 
|  | 167 | + } | 
|  | 168 | + ], | 
|  | 169 | + "source": [ | 
|  | 170 | + "e2f = {\"dog\":\"chein\",\"cat\":\"chat\",\"walrus\":\"morse\"}\n", | 
|  | 171 | + "type(e2f)" | 
|  | 172 | + ] | 
|  | 173 | + }, | 
|  | 174 | + { | 
|  | 175 | + "cell_type": "code", | 
|  | 176 | + "execution_count": 21, | 
|  | 177 | + "metadata": {}, | 
|  | 178 | + "outputs": [ | 
|  | 179 | + { | 
|  | 180 | + "name": "stdout", | 
|  | 181 | + "output_type": "stream", | 
|  | 182 | + "text": [ | 
|  | 183 | + "French word for walrus is morse\n" | 
|  | 184 | + ] | 
|  | 185 | + } | 
|  | 186 | + ], | 
|  | 187 | + "source": [ | 
|  | 188 | + "print(\"French word for walrus is \",e2f[\"walrus\"])" | 
|  | 189 | + ] | 
|  | 190 | + }, | 
|  | 191 | + { | 
|  | 192 | + "cell_type": "code", | 
|  | 193 | + "execution_count": 34, | 
|  | 194 | + "metadata": {}, | 
|  | 195 | + "outputs": [ | 
|  | 196 | + { | 
|  | 197 | + "name": "stdout", | 
|  | 198 | + "output_type": "stream", | 
|  | 199 | + "text": [ | 
|  | 200 | + "{'chein': 'dog', 'chat': 'cat', 'morse': 'walrus'}\n" | 
|  | 201 | + ] | 
|  | 202 | + } | 
|  | 203 | + ], | 
|  | 204 | + "source": [ | 
|  | 205 | + "f2e = {}\n", | 
|  | 206 | + "for english, french in e2f.items():\n", | 
|  | 207 | + " f2e[french] = english\n", | 
|  | 208 | + "print(f2e)" | 
|  | 209 | + ] | 
|  | 210 | + }, | 
|  | 211 | + { | 
|  | 212 | + "cell_type": "code", | 
|  | 213 | + "execution_count": 36, | 
|  | 214 | + "metadata": {}, | 
|  | 215 | + "outputs": [ | 
|  | 216 | + { | 
|  | 217 | + "name": "stdout", | 
|  | 218 | + "output_type": "stream", | 
|  | 219 | + "text": [ | 
|  | 220 | + "English version of the French word chien is dog\n" | 
|  | 221 | + ] | 
|  | 222 | + } | 
|  | 223 | + ], | 
|  | 224 | + "source": [ | 
|  | 225 | + "print(\"English version of the French word chien is \",f2e['chein'])" | 
|  | 226 | + ] | 
|  | 227 | + }, | 
|  | 228 | + { | 
|  | 229 | + "cell_type": "code", | 
|  | 230 | + "execution_count": 42, | 
|  | 231 | + "metadata": {}, | 
|  | 232 | + "outputs": [ | 
|  | 233 | + { | 
|  | 234 | + "data": { | 
|  | 235 | + "text/plain": [ | 
|  | 236 | + "dict_keys(['dog', 'cat', 'walrus'])" | 
|  | 237 | + ] | 
|  | 238 | + }, | 
|  | 239 | + "execution_count": 42, | 
|  | 240 | + "metadata": {}, | 
|  | 241 | + "output_type": "execute_result" | 
|  | 242 | + } | 
|  | 243 | + ], | 
|  | 244 | + "source": [ | 
|  | 245 | + "e2f.keys()" | 
|  | 246 | + ] | 
|  | 247 | + }, | 
|  | 248 | + { | 
|  | 249 | + "cell_type": "code", | 
|  | 250 | + "execution_count": 43, | 
|  | 251 | + "metadata": {}, | 
|  | 252 | + "outputs": [], | 
|  | 253 | + "source": [ | 
|  | 254 | + "life = {\n", | 
|  | 255 | + " 'animals': {\n", | 
|  | 256 | + " 'cats': ['Henri', 'Grumpy', 'Lucy'],\n", | 
|  | 257 | + " 'octopi': '',\n", | 
|  | 258 | + " 'emus': '',\n", | 
|  | 259 | + " },\n", | 
|  | 260 | + " 'plants': '',\n", | 
|  | 261 | + " 'other': ''\n", | 
|  | 262 | + " }" | 
|  | 263 | + ] | 
|  | 264 | + }, | 
|  | 265 | + { | 
|  | 266 | + "cell_type": "code", | 
|  | 267 | + "execution_count": 44, | 
|  | 268 | + "metadata": {}, | 
|  | 269 | + "outputs": [ | 
|  | 270 | + { | 
|  | 271 | + "data": { | 
|  | 272 | + "text/plain": [ | 
|  | 273 | + "dict_keys(['animals', 'plants', 'other'])" | 
|  | 274 | + ] | 
|  | 275 | + }, | 
|  | 276 | + "execution_count": 44, | 
|  | 277 | + "metadata": {}, | 
|  | 278 | + "output_type": "execute_result" | 
|  | 279 | + } | 
|  | 280 | + ], | 
|  | 281 | + "source": [ | 
|  | 282 | + "life.keys()" | 
|  | 283 | + ] | 
|  | 284 | + }, | 
|  | 285 | + { | 
|  | 286 | + "cell_type": "code", | 
|  | 287 | + "execution_count": 46, | 
|  | 288 | + "metadata": {}, | 
|  | 289 | + "outputs": [ | 
|  | 290 | + { | 
|  | 291 | + "data": { | 
|  | 292 | + "text/plain": [ | 
|  | 293 | + "dict_keys(['cats', 'octopi', 'emus'])" | 
|  | 294 | + ] | 
|  | 295 | + }, | 
|  | 296 | + "execution_count": 46, | 
|  | 297 | + "metadata": {}, | 
|  | 298 | + "output_type": "execute_result" | 
|  | 299 | + } | 
|  | 300 | + ], | 
|  | 301 | + "source": [ | 
|  | 302 | + "life.get('animals').keys()" | 
|  | 303 | + ] | 
|  | 304 | + }, | 
|  | 305 | + { | 
|  | 306 | + "cell_type": "code", | 
|  | 307 | + "execution_count": 48, | 
|  | 308 | + "metadata": {}, | 
|  | 309 | + "outputs": [ | 
|  | 310 | + { | 
|  | 311 | + "data": { | 
|  | 312 | + "text/plain": [ | 
|  | 313 | + "['Henri', 'Grumpy', 'Lucy']" | 
|  | 314 | + ] | 
|  | 315 | + }, | 
|  | 316 | + "execution_count": 48, | 
|  | 317 | + "metadata": {}, | 
|  | 318 | + "output_type": "execute_result" | 
|  | 319 | + } | 
|  | 320 | + ], | 
|  | 321 | + "source": [ | 
|  | 322 | + "life.get('animals').get('cats')" | 
|  | 323 | + ] | 
|  | 324 | + } | 
|  | 325 | + ], | 
|  | 326 | + "metadata": { | 
|  | 327 | + "kernelspec": { | 
|  | 328 | + "display_name": "Python 3", | 
|  | 329 | + "language": "python", | 
|  | 330 | + "name": "python3" | 
|  | 331 | + }, | 
|  | 332 | + "language_info": { | 
|  | 333 | + "codemirror_mode": { | 
|  | 334 | + "name": "ipython", | 
|  | 335 | + "version": 3 | 
|  | 336 | + }, | 
|  | 337 | + "file_extension": ".py", | 
|  | 338 | + "mimetype": "text/x-python", | 
|  | 339 | + "name": "python", | 
|  | 340 | + "nbconvert_exporter": "python", | 
|  | 341 | + "pygments_lexer": "ipython3", | 
|  | 342 | + "version": "3.8.5" | 
|  | 343 | + } | 
|  | 344 | + }, | 
|  | 345 | + "nbformat": 4, | 
|  | 346 | + "nbformat_minor": 4 | 
|  | 347 | +} | 
0 commit comments