├── README.md ├── Lab Practice.ipynb ├── BootCamp_First_Class_31_July_2023.ipynb ├── Dictionaries & Sets In Python..ipynb └── List In Python.ipynb /README.md: -------------------------------------------------------------------------------- 1 | # Data Science & AI Bootcamp 2 | -------------------------------------------------------------------------------- /Lab Practice.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Topic: print()" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "1) Using the python print function print any string value, integer value, boolean value, float value in single print command" 15 | ] 16 | }, 17 | { 18 | "cell_type": "code", 19 | "execution_count": 52, 20 | "metadata": {}, 21 | "outputs": [ 22 | { 23 | "name": "stdout", 24 | "output_type": "stream", 25 | "text": [ 26 | "Sajid Majeed 123 True 34.6\n" 27 | ] 28 | } 29 | ], 30 | "source": [ 31 | "# type your code here\n", 32 | "print(\"Sajid Majeed\", 123, True, 34.6)" 33 | ] 34 | }, 35 | { 36 | "cell_type": "markdown", 37 | "metadata": {}, 38 | "source": [ 39 | "2) Using the python print function print hyphon(-) separated any string value, integer value, boolean value, float value in single print command" 40 | ] 41 | }, 42 | { 43 | "cell_type": "code", 44 | "execution_count": 53, 45 | "metadata": {}, 46 | "outputs": [ 47 | { 48 | "name": "stdout", 49 | "output_type": "stream", 50 | "text": [ 51 | "Sajid Majeed-123-True-34.6\n" 52 | ] 53 | } 54 | ], 55 | "source": [ 56 | "# type your code here\n", 57 | "print(\"Sajid Majeed\", 123, True, 34.6, sep=\"-\")" 58 | ] 59 | }, 60 | { 61 | "cell_type": "markdown", 62 | "metadata": {}, 63 | "source": [ 64 | "3) Using the python print function print any string value, integer value, boolean value, float value in separate print command.\n", 65 | "But every value must be space separated and in single line " 66 | ] 67 | }, 68 | { 69 | "cell_type": "code", 70 | "execution_count": 54, 71 | "metadata": {}, 72 | "outputs": [ 73 | { 74 | "name": "stdout", 75 | "output_type": "stream", 76 | "text": [ 77 | "Sajid Majeed\n", 78 | "123\n", 79 | "True\n", 80 | "34.6\n" 81 | ] 82 | } 83 | ], 84 | "source": [ 85 | "# type your code here\n", 86 | "print(\"Sajid Majeed\", sep=\" \")\n", 87 | "print(123, sep=\" \")\n", 88 | "print(True, sep=\" \")\n", 89 | "print(34.6, sep=\" \")" 90 | ] 91 | }, 92 | { 93 | "cell_type": "code", 94 | "execution_count": 1, 95 | "metadata": {}, 96 | "outputs": [ 97 | { 98 | "name": "stdout", 99 | "output_type": "stream", 100 | "text": [ 101 | "\n" 102 | ] 103 | } 104 | ], 105 | "source": [ 106 | "# type your answer here\n", 107 | "print()" 108 | ] 109 | }, 110 | { 111 | "cell_type": "markdown", 112 | "metadata": {}, 113 | "source": [ 114 | "# TOPIC :Variables in Python Operators" 115 | ] 116 | }, 117 | { 118 | "cell_type": "markdown", 119 | "metadata": {}, 120 | "source": [ 121 | "5) One of my friends name is Mr. Ahmed. He is 30 years old. He is a lawer by profession. He has done his bachelors in law in the year 2005. He is working with a reputable law firm 'The Himalya Associates' in Karachi since 2015.\n", 122 | "He is a handsome lawer with height of 5.10 feets and weight 70600g. His monthly income is Rs. 200k PKR.\n", 123 | "\n", 124 | "Note: Create variables from above text and also assign values from the text. " 125 | ] 126 | }, 127 | { 128 | "cell_type": "code", 129 | "execution_count": 56, 130 | "metadata": {}, 131 | "outputs": [], 132 | "source": [ 133 | "#type your code here\n", 134 | "friend_name= \"Mr. Ahmed\"\n", 135 | "age= 30\n", 136 | "profession= \"Lawyer\"\n", 137 | "degree= \"Bachelor in law\"\n", 138 | "passout_year= 2005\n", 139 | "firm= \"The Himalya Associates\"\n", 140 | "firm_joining_year= 2015\n", 141 | "Height_ft= 5.10\n", 142 | "Weight_gm= 70600\n", 143 | "monthly_income_pkr= 200000\n", 144 | "is_professional= True" 145 | ] 146 | }, 147 | { 148 | "cell_type": "markdown", 149 | "metadata": {}, 150 | "source": [ 151 | "6)How many years has been to Mr. Ahmed after his bachelors degree? Create a variable that hold current year value and then subtract it from his passout year" 152 | ] 153 | }, 154 | { 155 | "cell_type": "code", 156 | "execution_count": 62, 157 | "metadata": {}, 158 | "outputs": [ 159 | { 160 | "name": "stdout", 161 | "output_type": "stream", 162 | "text": [ 163 | " From 18 years ago Mr. Ahmed passed his Bachelors degree\n" 164 | ] 165 | } 166 | ], 167 | "source": [ 168 | "#type your code here \n", 169 | "current_year =2023\n", 170 | "passout_year= 2005\n", 171 | "print(f\" From {current_year-passout_year} years ago Mr. Ahmed passed his Bachelors degree\")" 172 | ] 173 | }, 174 | { 175 | "cell_type": "markdown", 176 | "metadata": {}, 177 | "source": [ 178 | "7) How many years has Mr. Ahmed been working with law firm 'The Himalya Associates'. Create necesary variables and print the correct number of years in working in the firm" 179 | ] 180 | }, 181 | { 182 | "cell_type": "code", 183 | "execution_count": 58, 184 | "metadata": {}, 185 | "outputs": [ 186 | { 187 | "name": "stdout", 188 | "output_type": "stream", 189 | "text": [ 190 | "From 8 years Mr. Ahmed has been working with law firm 'The Himalya Associates\n" 191 | ] 192 | } 193 | ], 194 | "source": [ 195 | "#type your code here \n", 196 | "current_year =2023\n", 197 | "firm_joining_year= 2015\n", 198 | "print(f\"From {current_year-firm_joining_year} years Mr. Ahmed has been working with law firm 'The Himalya Associates\")" 199 | ] 200 | }, 201 | { 202 | "cell_type": "markdown", 203 | "metadata": {}, 204 | "source": [ 205 | "8)Convert the monthly income of Mr. Ahmed in dollars. Create necesary variables and print the income in dollars." 206 | ] 207 | }, 208 | { 209 | "cell_type": "code", 210 | "execution_count": 37, 211 | "metadata": {}, 212 | "outputs": [ 213 | { 214 | "name": "stdout", 215 | "output_type": "stream", 216 | "text": [ 217 | "701.7543859649123\n", 218 | "701.75\n", 219 | "702\n", 220 | "701\n" 221 | ] 222 | } 223 | ], 224 | "source": [ 225 | "#type your code here \n", 226 | "monthly_income_pkr= 200000\n", 227 | "monthly_income_usd=monthly_income_pkr/285\n", 228 | "print(monthly_income_usd)\n", 229 | "\n", 230 | "print(round(monthly_income_usd,2))\n", 231 | "import math\n", 232 | "print(math.ceil((monthly_income_usd)))\n", 233 | "print(math.floor((monthly_income_usd)))" 234 | ] 235 | }, 236 | { 237 | "cell_type": "markdown", 238 | "metadata": {}, 239 | "source": [ 240 | "9) Check if the income in dollars is a float or integer value. if it is float, re-write the code so that income gets converted in integer. print the income in integer type value" 241 | ] 242 | }, 243 | { 244 | "cell_type": "code", 245 | "execution_count": 38, 246 | "metadata": {}, 247 | "outputs": [ 248 | { 249 | "name": "stdout", 250 | "output_type": "stream", 251 | "text": [ 252 | "701.7543859649123\n", 253 | "\n", 254 | "701\n", 255 | "\n" 256 | ] 257 | } 258 | ], 259 | "source": [ 260 | "#type your code here \n", 261 | "print(monthly_income_usd)\n", 262 | "print(type(monthly_income_usd))\n", 263 | "converted_value =int(monthly_income_usd)\n", 264 | "print(converted_value)\n", 265 | "print(type(converted_value))" 266 | ] 267 | }, 268 | { 269 | "cell_type": "raw", 270 | "metadata": {}, 271 | "source": [ 272 | "10) Print the type of Mr. Ahmed's weight. Convert the weight of Mr. Ahmed in kg so that weight must be a integer value. " 273 | ] 274 | }, 275 | { 276 | "cell_type": "code", 277 | "execution_count": 42, 278 | "metadata": {}, 279 | "outputs": [ 280 | { 281 | "name": "stdout", 282 | "output_type": "stream", 283 | "text": [ 284 | "70600\n", 285 | "70\n" 286 | ] 287 | } 288 | ], 289 | "source": [ 290 | "#type your code here \n", 291 | "print(Weight_gm)\n", 292 | "type(Weight_gm)\n", 293 | "weight_in_kg = int (Weight_gm /1000)\n", 294 | "print(weight_in_kg)" 295 | ] 296 | }, 297 | { 298 | "cell_type": "raw", 299 | "metadata": {}, 300 | "source": [ 301 | "11) print the year of birth of Mr. Ahmed." 302 | ] 303 | }, 304 | { 305 | "cell_type": "code", 306 | "execution_count": 51, 307 | "metadata": {}, 308 | "outputs": [ 309 | { 310 | "data": { 311 | "text/plain": [ 312 | "1993" 313 | ] 314 | }, 315 | "execution_count": 51, 316 | "metadata": {}, 317 | "output_type": "execute_result" 318 | } 319 | ], 320 | "source": [ 321 | "#type your code here\n", 322 | "birt_year = current_year -age\n", 323 | "birth_year" 324 | ] 325 | }, 326 | { 327 | "cell_type": "markdown", 328 | "metadata": {}, 329 | "source": [ 330 | "12) Can Rs. 100 be divided equally among 6 students? \n", 331 | "HINT: % operator" 332 | ] 333 | }, 334 | { 335 | "cell_type": "code", 336 | "execution_count": 48, 337 | "metadata": {}, 338 | "outputs": [ 339 | { 340 | "data": { 341 | "text/plain": [ 342 | "4" 343 | ] 344 | }, 345 | "execution_count": 48, 346 | "metadata": {}, 347 | "output_type": "execute_result" 348 | } 349 | ], 350 | "source": [ 351 | "#type your code here \n", 352 | "100%6\n" 353 | ] 354 | } 355 | ], 356 | "metadata": { 357 | "kernelspec": { 358 | "display_name": "Python 3", 359 | "language": "python", 360 | "name": "python3" 361 | }, 362 | "language_info": { 363 | "codemirror_mode": { 364 | "name": "ipython", 365 | "version": 3 366 | }, 367 | "file_extension": ".py", 368 | "mimetype": "text/x-python", 369 | "name": "python", 370 | "nbconvert_exporter": "python", 371 | "pygments_lexer": "ipython3", 372 | "version": "3.7.4" 373 | } 374 | }, 375 | "nbformat": 4, 376 | "nbformat_minor": 2 377 | } 378 | -------------------------------------------------------------------------------- /BootCamp_First_Class_31_July_2023.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 1, 6 | "metadata": {}, 7 | "outputs": [ 8 | { 9 | "name": "stdout", 10 | "output_type": "stream", 11 | "text": [ 12 | "abc\n" 13 | ] 14 | } 15 | ], 16 | "source": [ 17 | "print(\"abc\")" 18 | ] 19 | }, 20 | { 21 | "cell_type": "code", 22 | "execution_count": 3, 23 | "metadata": {}, 24 | "outputs": [ 25 | { 26 | "data": { 27 | "text/plain": [ 28 | "int" 29 | ] 30 | }, 31 | "execution_count": 3, 32 | "metadata": {}, 33 | "output_type": "execute_result" 34 | } 35 | ], 36 | "source": [ 37 | "type(123)" 38 | ] 39 | }, 40 | { 41 | "cell_type": "code", 42 | "execution_count": 4, 43 | "metadata": {}, 44 | "outputs": [], 45 | "source": [ 46 | "country = \"Pakistan\"" 47 | ] 48 | }, 49 | { 50 | "cell_type": "code", 51 | "execution_count": 5, 52 | "metadata": {}, 53 | "outputs": [ 54 | { 55 | "data": { 56 | "text/plain": [ 57 | "str" 58 | ] 59 | }, 60 | "execution_count": 5, 61 | "metadata": {}, 62 | "output_type": "execute_result" 63 | } 64 | ], 65 | "source": [ 66 | "type(country)" 67 | ] 68 | }, 69 | { 70 | "cell_type": "code", 71 | "execution_count": 6, 72 | "metadata": {}, 73 | "outputs": [ 74 | { 75 | "data": { 76 | "text/plain": [ 77 | "8" 78 | ] 79 | }, 80 | "execution_count": 6, 81 | "metadata": {}, 82 | "output_type": "execute_result" 83 | } 84 | ], 85 | "source": [ 86 | "len(country)" 87 | ] 88 | }, 89 | { 90 | "cell_type": "code", 91 | "execution_count": 10, 92 | "metadata": {}, 93 | "outputs": [ 94 | { 95 | "data": { 96 | "text/plain": [ 97 | "1" 98 | ] 99 | }, 100 | "execution_count": 10, 101 | "metadata": {}, 102 | "output_type": "execute_result" 103 | } 104 | ], 105 | "source": [ 106 | "country.count('ak')" 107 | ] 108 | }, 109 | { 110 | "cell_type": "code", 111 | "execution_count": 12, 112 | "metadata": {}, 113 | "outputs": [ 114 | { 115 | "data": { 116 | "text/plain": [ 117 | "1" 118 | ] 119 | }, 120 | "execution_count": 12, 121 | "metadata": {}, 122 | "output_type": "execute_result" 123 | } 124 | ], 125 | "source": [ 126 | "country.count('P')" 127 | ] 128 | }, 129 | { 130 | "cell_type": "code", 131 | "execution_count": 13, 132 | "metadata": {}, 133 | "outputs": [ 134 | { 135 | "data": { 136 | "text/plain": [ 137 | "" 138 | ] 139 | }, 140 | "execution_count": 13, 141 | "metadata": {}, 142 | "output_type": "execute_result" 143 | } 144 | ], 145 | "source": [ 146 | "country.find" 147 | ] 148 | }, 149 | { 150 | "cell_type": "code", 151 | "execution_count": 15, 152 | "metadata": {}, 153 | "outputs": [ 154 | { 155 | "data": { 156 | "text/plain": [ 157 | "1" 158 | ] 159 | }, 160 | "execution_count": 15, 161 | "metadata": {}, 162 | "output_type": "execute_result" 163 | } 164 | ], 165 | "source": [ 166 | "country.find('a')" 167 | ] 168 | }, 169 | { 170 | "cell_type": "code", 171 | "execution_count": 16, 172 | "metadata": {}, 173 | "outputs": [ 174 | { 175 | "data": { 176 | "text/plain": [ 177 | "2" 178 | ] 179 | }, 180 | "execution_count": 16, 181 | "metadata": {}, 182 | "output_type": "execute_result" 183 | } 184 | ], 185 | "source": [ 186 | "country.count('a')" 187 | ] 188 | }, 189 | { 190 | "cell_type": "code", 191 | "execution_count": 17, 192 | "metadata": {}, 193 | "outputs": [ 194 | { 195 | "data": { 196 | "text/plain": [ 197 | "6" 198 | ] 199 | }, 200 | "execution_count": 17, 201 | "metadata": {}, 202 | "output_type": "execute_result" 203 | } 204 | ], 205 | "source": [ 206 | "country.find('a',2)" 207 | ] 208 | }, 209 | { 210 | "cell_type": "code", 211 | "execution_count": 21, 212 | "metadata": {}, 213 | "outputs": [ 214 | { 215 | "data": { 216 | "text/plain": [ 217 | "True" 218 | ] 219 | }, 220 | "execution_count": 21, 221 | "metadata": {}, 222 | "output_type": "execute_result" 223 | } 224 | ], 225 | "source": [ 226 | "country.isalpha()" 227 | ] 228 | }, 229 | { 230 | "cell_type": "code", 231 | "execution_count": 22, 232 | "metadata": {}, 233 | "outputs": [ 234 | { 235 | "data": { 236 | "text/plain": [ 237 | "True" 238 | ] 239 | }, 240 | "execution_count": 22, 241 | "metadata": {}, 242 | "output_type": "execute_result" 243 | } 244 | ], 245 | "source": [ 246 | "\"country\".isalpha()" 247 | ] 248 | }, 249 | { 250 | "cell_type": "code", 251 | "execution_count": 23, 252 | "metadata": {}, 253 | "outputs": [ 254 | { 255 | "data": { 256 | "text/plain": [ 257 | "True" 258 | ] 259 | }, 260 | "execution_count": 23, 261 | "metadata": {}, 262 | "output_type": "execute_result" 263 | } 264 | ], 265 | "source": [ 266 | "\"country\".isalnum()" 267 | ] 268 | }, 269 | { 270 | "cell_type": "code", 271 | "execution_count": 24, 272 | "metadata": {}, 273 | "outputs": [ 274 | { 275 | "data": { 276 | "text/plain": [ 277 | "False" 278 | ] 279 | }, 280 | "execution_count": 24, 281 | "metadata": {}, 282 | "output_type": "execute_result" 283 | } 284 | ], 285 | "source": [ 286 | "\"country\".isnumeric()" 287 | ] 288 | }, 289 | { 290 | "cell_type": "code", 291 | "execution_count": 26, 292 | "metadata": {}, 293 | "outputs": [ 294 | { 295 | "data": { 296 | "text/plain": [ 297 | "True" 298 | ] 299 | }, 300 | "execution_count": 26, 301 | "metadata": {}, 302 | "output_type": "execute_result" 303 | } 304 | ], 305 | "source": [ 306 | "\"country\".isidentifier()" 307 | ] 308 | }, 309 | { 310 | "cell_type": "code", 311 | "execution_count": 27, 312 | "metadata": {}, 313 | "outputs": [ 314 | { 315 | "data": { 316 | "text/plain": [ 317 | "False" 318 | ] 319 | }, 320 | "execution_count": 27, 321 | "metadata": {}, 322 | "output_type": "execute_result" 323 | } 324 | ], 325 | "source": [ 326 | "\"country\".istitle()" 327 | ] 328 | }, 329 | { 330 | "cell_type": "code", 331 | "execution_count": 28, 332 | "metadata": {}, 333 | "outputs": [ 334 | { 335 | "data": { 336 | "text/plain": [ 337 | "True" 338 | ] 339 | }, 340 | "execution_count": 28, 341 | "metadata": {}, 342 | "output_type": "execute_result" 343 | } 344 | ], 345 | "source": [ 346 | "country.istitle()" 347 | ] 348 | }, 349 | { 350 | "cell_type": "code", 351 | "execution_count": 29, 352 | "metadata": {}, 353 | "outputs": [ 354 | { 355 | "data": { 356 | "text/plain": [ 357 | "False" 358 | ] 359 | }, 360 | "execution_count": 29, 361 | "metadata": {}, 362 | "output_type": "execute_result" 363 | } 364 | ], 365 | "source": [ 366 | "country.isdecimal()" 367 | ] 368 | }, 369 | { 370 | "cell_type": "code", 371 | "execution_count": 30, 372 | "metadata": {}, 373 | "outputs": [ 374 | { 375 | "data": { 376 | "text/plain": [ 377 | "True" 378 | ] 379 | }, 380 | "execution_count": 30, 381 | "metadata": {}, 382 | "output_type": "execute_result" 383 | } 384 | ], 385 | "source": [ 386 | "country.isprintable()" 387 | ] 388 | }, 389 | { 390 | "cell_type": "code", 391 | "execution_count": 31, 392 | "metadata": {}, 393 | "outputs": [ 394 | { 395 | "data": { 396 | "text/plain": [ 397 | "True" 398 | ] 399 | }, 400 | "execution_count": 31, 401 | "metadata": {}, 402 | "output_type": "execute_result" 403 | } 404 | ], 405 | "source": [ 406 | "country.isascii()" 407 | ] 408 | }, 409 | { 410 | "cell_type": "code", 411 | "execution_count": 32, 412 | "metadata": {}, 413 | "outputs": [ 414 | { 415 | "data": { 416 | "text/plain": [ 417 | "True" 418 | ] 419 | }, 420 | "execution_count": 32, 421 | "metadata": {}, 422 | "output_type": "execute_result" 423 | } 424 | ], 425 | "source": [ 426 | "country.isidentifier()" 427 | ] 428 | }, 429 | { 430 | "cell_type": "code", 431 | "execution_count": 35, 432 | "metadata": {}, 433 | "outputs": [], 434 | "source": [ 435 | "text = \"Hello we are all pythoneers\"" 436 | ] 437 | }, 438 | { 439 | "cell_type": "code", 440 | "execution_count": 36, 441 | "metadata": {}, 442 | "outputs": [ 443 | { 444 | "data": { 445 | "text/plain": [ 446 | "['Hello', 'we', 'are', 'all', 'pythoneers']" 447 | ] 448 | }, 449 | "execution_count": 36, 450 | "metadata": {}, 451 | "output_type": "execute_result" 452 | } 453 | ], 454 | "source": [ 455 | "text.split(' ')" 456 | ] 457 | }, 458 | { 459 | "cell_type": "code", 460 | "execution_count": 37, 461 | "metadata": {}, 462 | "outputs": [], 463 | "source": [ 464 | "splitted = text.split(' ')" 465 | ] 466 | }, 467 | { 468 | "cell_type": "code", 469 | "execution_count": 39, 470 | "metadata": {}, 471 | "outputs": [ 472 | { 473 | "name": "stdout", 474 | "output_type": "stream", 475 | "text": [ 476 | "['Hello', 'we', 'are', 'all', 'pythoneers']\n" 477 | ] 478 | } 479 | ], 480 | "source": [ 481 | "print(splitted)" 482 | ] 483 | }, 484 | { 485 | "cell_type": "code", 486 | "execution_count": 38, 487 | "metadata": {}, 488 | "outputs": [ 489 | { 490 | "data": { 491 | "text/plain": [ 492 | "'Hello we are all pythoneers'" 493 | ] 494 | }, 495 | "execution_count": 38, 496 | "metadata": {}, 497 | "output_type": "execute_result" 498 | } 499 | ], 500 | "source": [ 501 | "' '.join(splitted)" 502 | ] 503 | }, 504 | { 505 | "cell_type": "code", 506 | "execution_count": 40, 507 | "metadata": {}, 508 | "outputs": [ 509 | { 510 | "data": { 511 | "text/plain": [ 512 | "'Hello we are all PYHTONEERS'" 513 | ] 514 | }, 515 | "execution_count": 40, 516 | "metadata": {}, 517 | "output_type": "execute_result" 518 | } 519 | ], 520 | "source": [ 521 | "text.replace('pythoneers','PYHTONEERS')" 522 | ] 523 | }, 524 | { 525 | "cell_type": "code", 526 | "execution_count": 41, 527 | "metadata": {}, 528 | "outputs": [ 529 | { 530 | "data": { 531 | "text/plain": [ 532 | "'Hello we are all pythoneers'" 533 | ] 534 | }, 535 | "execution_count": 41, 536 | "metadata": {}, 537 | "output_type": "execute_result" 538 | } 539 | ], 540 | "source": [ 541 | "text" 542 | ] 543 | }, 544 | { 545 | "cell_type": "code", 546 | "execution_count": 42, 547 | "metadata": {}, 548 | "outputs": [], 549 | "source": [ 550 | "name = \" Sajid Majeed \"" 551 | ] 552 | }, 553 | { 554 | "cell_type": "code", 555 | "execution_count": 43, 556 | "metadata": {}, 557 | "outputs": [ 558 | { 559 | "data": { 560 | "text/plain": [ 561 | "False" 562 | ] 563 | }, 564 | "execution_count": 43, 565 | "metadata": {}, 566 | "output_type": "execute_result" 567 | } 568 | ], 569 | "source": [ 570 | "name=='Sajid Majeed'" 571 | ] 572 | }, 573 | { 574 | "cell_type": "code", 575 | "execution_count": 44, 576 | "metadata": {}, 577 | "outputs": [ 578 | { 579 | "data": { 580 | "text/plain": [ 581 | "'Sajid Majeed '" 582 | ] 583 | }, 584 | "execution_count": 44, 585 | "metadata": {}, 586 | "output_type": "execute_result" 587 | } 588 | ], 589 | "source": [ 590 | "name.lstrip()" 591 | ] 592 | }, 593 | { 594 | "cell_type": "code", 595 | "execution_count": 45, 596 | "metadata": {}, 597 | "outputs": [ 598 | { 599 | "data": { 600 | "text/plain": [ 601 | "' Sajid Majeed'" 602 | ] 603 | }, 604 | "execution_count": 45, 605 | "metadata": {}, 606 | "output_type": "execute_result" 607 | } 608 | ], 609 | "source": [ 610 | "name.rstrip()" 611 | ] 612 | }, 613 | { 614 | "cell_type": "code", 615 | "execution_count": 46, 616 | "metadata": {}, 617 | "outputs": [ 618 | { 619 | "data": { 620 | "text/plain": [ 621 | "'Sajid Majeed'" 622 | ] 623 | }, 624 | "execution_count": 46, 625 | "metadata": {}, 626 | "output_type": "execute_result" 627 | } 628 | ], 629 | "source": [ 630 | "name.strip()" 631 | ] 632 | }, 633 | { 634 | "cell_type": "code", 635 | "execution_count": 47, 636 | "metadata": {}, 637 | "outputs": [ 638 | { 639 | "data": { 640 | "text/plain": [ 641 | "7" 642 | ] 643 | }, 644 | "execution_count": 47, 645 | "metadata": {}, 646 | "output_type": "execute_result" 647 | } 648 | ], 649 | "source": [ 650 | "name.index(\"M\")" 651 | ] 652 | }, 653 | { 654 | "cell_type": "code", 655 | "execution_count": 48, 656 | "metadata": {}, 657 | "outputs": [], 658 | "source": [ 659 | "name = \" Sajid Majeed \"\n", 660 | "age = 30\n" 661 | ] 662 | }, 663 | { 664 | "cell_type": "code", 665 | "execution_count": 68, 666 | "metadata": {}, 667 | "outputs": [ 668 | { 669 | "data": { 670 | "text/plain": [ 671 | "'Hello myself is Sajid Majeed . I am 30 year old'" 672 | ] 673 | }, 674 | "execution_count": 68, 675 | "metadata": {}, 676 | "output_type": "execute_result" 677 | } 678 | ], 679 | "source": [ 680 | "\"Hello myself is\" +name +\". I am \" + str(age) + \" year old\"" 681 | ] 682 | }, 683 | { 684 | "cell_type": "markdown", 685 | "metadata": {}, 686 | "source": [ 687 | "String Formation" 688 | ] 689 | }, 690 | { 691 | "cell_type": "code", 692 | "execution_count": 69, 693 | "metadata": {}, 694 | "outputs": [ 695 | { 696 | "data": { 697 | "text/plain": [ 698 | "'Hello myself is Sajid Majeed . I am 30 year old'" 699 | ] 700 | }, 701 | "execution_count": 69, 702 | "metadata": {}, 703 | "output_type": "execute_result" 704 | } 705 | ], 706 | "source": [ 707 | "\"Hello myself is {}. I am {} year old\".format(name,age)" 708 | ] 709 | }, 710 | { 711 | "cell_type": "code", 712 | "execution_count": 78, 713 | "metadata": {}, 714 | "outputs": [ 715 | { 716 | "data": { 717 | "text/plain": [ 718 | "'Hello myself is Sajid Majeed .I am 30 year old'" 719 | ] 720 | }, 721 | "execution_count": 78, 722 | "metadata": {}, 723 | "output_type": "execute_result" 724 | } 725 | ], 726 | "source": [ 727 | "f\"Hello myself is {name}.I am {age} year old\"" 728 | ] 729 | }, 730 | { 731 | "cell_type": "code", 732 | "execution_count": 79, 733 | "metadata": {}, 734 | "outputs": [ 735 | { 736 | "name": "stdout", 737 | "output_type": "stream", 738 | "text": [ 739 | "Hello World\n", 740 | "Hello World\n", 741 | "Hello World\n", 742 | "Hello World\n" 743 | ] 744 | } 745 | ], 746 | "source": [ 747 | "print ('Hello World')\n", 748 | "print (\"Hello World\")\n", 749 | "print('''Hello World''')\n", 750 | "print(\"\"\"Hello World\"\"\")" 751 | ] 752 | }, 753 | { 754 | "cell_type": "code", 755 | "execution_count": 80, 756 | "metadata": {}, 757 | "outputs": [ 758 | { 759 | "name": "stdout", 760 | "output_type": "stream", 761 | "text": [ 762 | "We are all Learning 'Python and Data Science'\n" 763 | ] 764 | } 765 | ], 766 | "source": [ 767 | "print(\"We are all Learning 'Python and Data Science'\")" 768 | ] 769 | }, 770 | { 771 | "cell_type": "code", 772 | "execution_count": 81, 773 | "metadata": {}, 774 | "outputs": [ 775 | { 776 | "name": "stdout", 777 | "output_type": "stream", 778 | "text": [ 779 | "We are all Learning \"Python and Data Science\"\n" 780 | ] 781 | } 782 | ], 783 | "source": [ 784 | "print('We are all Learning \"Python and Data Science\"')" 785 | ] 786 | }, 787 | { 788 | "cell_type": "code", 789 | "execution_count": 89, 790 | "metadata": {}, 791 | "outputs": [ 792 | { 793 | "name": "stdout", 794 | "output_type": "stream", 795 | "text": [ 796 | "Please Enter Your Name :Sajid Majeed\n", 797 | "Please Enter Course Name :Data Science & AI\n", 798 | "Please Enter Venue Name :SSUET\n", 799 | "Please Enter Course Timing :9:00am to 5:00pm\n", 800 | "\n", 801 | "\n", 802 | " ========================================================\n", 803 | " High Impact Skills Bootcamp\n", 804 | " ========================================================\n", 805 | " \n", 806 | " Candidate Name : Sajid Majeed\n", 807 | " Course Name : Data Science & AI\n", 808 | " Course Venue : SSUET\n", 809 | " Course Timing : 9:00am to 5:00pm\n", 810 | " \n", 811 | " ========================================================\n", 812 | " Note : If found Please return to SSUET\n", 813 | " ========================================================\n", 814 | "\n", 815 | "\n" 816 | ] 817 | } 818 | ], 819 | "source": [ 820 | "name = input(\"Please Enter Your Name :\")\n", 821 | "course_name = input(\"Please Enter Course Name :\")\n", 822 | "venue_name = input(\"Please Enter Venue Name :\")\n", 823 | "course_timing = input(\"Please Enter Course Timing :\")\n", 824 | "\n", 825 | "print(f\"\"\"\n", 826 | "\n", 827 | " ========================================================\n", 828 | " High Impact Skills Bootcamp\n", 829 | " ========================================================\n", 830 | " \n", 831 | " Candidate Name : {name}\n", 832 | " Course Name : {course_name}\n", 833 | " Course Venue : {venue_name}\n", 834 | " Course Timing : {course_timing}\n", 835 | " \n", 836 | " ========================================================\n", 837 | " Note : If found Please return to {venue_name}\n", 838 | " ========================================================\n", 839 | "\n", 840 | "\"\"\")" 841 | ] 842 | }, 843 | { 844 | "cell_type": "code", 845 | "execution_count": 92, 846 | "metadata": {}, 847 | "outputs": [ 848 | { 849 | "data": { 850 | "text/plain": [ 851 | "5" 852 | ] 853 | }, 854 | "execution_count": 92, 855 | "metadata": {}, 856 | "output_type": "execute_result" 857 | } 858 | ], 859 | "source": [ 860 | "2+3" 861 | ] 862 | }, 863 | { 864 | "cell_type": "code", 865 | "execution_count": 95, 866 | "metadata": {}, 867 | "outputs": [ 868 | { 869 | "data": { 870 | "text/plain": [ 871 | "50" 872 | ] 873 | }, 874 | "execution_count": 95, 875 | "metadata": {}, 876 | "output_type": "execute_result" 877 | } 878 | ], 879 | "source": [ 880 | "a=100\n", 881 | "b= 200\n", 882 | "c = 50\n", 883 | "a and b and c" 884 | ] 885 | }, 886 | { 887 | "cell_type": "code", 888 | "execution_count": 96, 889 | "metadata": {}, 890 | "outputs": [ 891 | { 892 | "data": { 893 | "text/plain": [ 894 | "100" 895 | ] 896 | }, 897 | "execution_count": 96, 898 | "metadata": {}, 899 | "output_type": "execute_result" 900 | } 901 | ], 902 | "source": [ 903 | "a=100\n", 904 | "b= 200\n", 905 | "c = 50\n", 906 | "a or b or c" 907 | ] 908 | }, 909 | { 910 | "cell_type": "code", 911 | "execution_count": 98, 912 | "metadata": {}, 913 | "outputs": [ 914 | { 915 | "data": { 916 | "text/plain": [ 917 | "False" 918 | ] 919 | }, 920 | "execution_count": 98, 921 | "metadata": {}, 922 | "output_type": "execute_result" 923 | } 924 | ], 925 | "source": [ 926 | "x= -100\n", 927 | "from math import sqrt\n", 928 | "x>0 and sqrt(x)" 929 | ] 930 | }, 931 | { 932 | "cell_type": "code", 933 | "execution_count": 99, 934 | "metadata": {}, 935 | "outputs": [ 936 | { 937 | "ename": "ValueError", 938 | "evalue": "math domain error", 939 | "output_type": "error", 940 | "traceback": [ 941 | "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", 942 | "\u001b[1;31mValueError\u001b[0m Traceback (most recent call last)", 943 | "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[0mx\u001b[0m\u001b[1;33m=\u001b[0m \u001b[1;33m-\u001b[0m\u001b[1;36m100\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 2\u001b[0m \u001b[1;32mfrom\u001b[0m \u001b[0mmath\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0msqrt\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 3\u001b[1;33m \u001b[0mx\u001b[0m\u001b[1;33m<\u001b[0m\u001b[1;36m0\u001b[0m \u001b[1;32mand\u001b[0m \u001b[0msqrt\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mx\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", 944 | "\u001b[1;31mValueError\u001b[0m: math domain error" 945 | ] 946 | } 947 | ], 948 | "source": [ 949 | "x= -100\n", 950 | "from math import sqrt\n", 951 | "x<0 and sqrt(x)" 952 | ] 953 | }, 954 | { 955 | "cell_type": "code", 956 | "execution_count": 100, 957 | "metadata": {}, 958 | "outputs": [ 959 | { 960 | "data": { 961 | "text/plain": [ 962 | "True" 963 | ] 964 | }, 965 | "execution_count": 100, 966 | "metadata": {}, 967 | "output_type": "execute_result" 968 | } 969 | ], 970 | "source": [ 971 | "a=100\n", 972 | "b =a\n", 973 | "b is a" 974 | ] 975 | }, 976 | { 977 | "cell_type": "code", 978 | "execution_count": 102, 979 | "metadata": {}, 980 | "outputs": [ 981 | { 982 | "data": { 983 | "text/plain": [ 984 | "True" 985 | ] 986 | }, 987 | "execution_count": 102, 988 | "metadata": {}, 989 | "output_type": "execute_result" 990 | } 991 | ], 992 | "source": [ 993 | "c =100 \n", 994 | "b is c" 995 | ] 996 | }, 997 | { 998 | "cell_type": "code", 999 | "execution_count": 115, 1000 | "metadata": {}, 1001 | "outputs": [ 1002 | { 1003 | "data": { 1004 | "text/plain": [ 1005 | "True" 1006 | ] 1007 | }, 1008 | "execution_count": 115, 1009 | "metadata": {}, 1010 | "output_type": "execute_result" 1011 | } 1012 | ], 1013 | "source": [ 1014 | "2 < 3 and 5**2 not in [1,2,3,4,5] " 1015 | ] 1016 | }, 1017 | { 1018 | "cell_type": "code", 1019 | "execution_count": 119, 1020 | "metadata": {}, 1021 | "outputs": [ 1022 | { 1023 | "data": { 1024 | "text/plain": [ 1025 | "500" 1026 | ] 1027 | }, 1028 | "execution_count": 119, 1029 | "metadata": {}, 1030 | "output_type": "execute_result" 1031 | } 1032 | ], 1033 | "source": [ 1034 | "x = 100\n", 1035 | "x*=5\n", 1036 | "x" 1037 | ] 1038 | }, 1039 | { 1040 | "cell_type": "code", 1041 | "execution_count": 120, 1042 | "metadata": {}, 1043 | "outputs": [ 1044 | { 1045 | "data": { 1046 | "text/plain": [ 1047 | "105" 1048 | ] 1049 | }, 1050 | "execution_count": 120, 1051 | "metadata": {}, 1052 | "output_type": "execute_result" 1053 | } 1054 | ], 1055 | "source": [ 1056 | "x = 100\n", 1057 | "x+=5\n", 1058 | "x" 1059 | ] 1060 | }, 1061 | { 1062 | "cell_type": "code", 1063 | "execution_count": null, 1064 | "metadata": {}, 1065 | "outputs": [], 1066 | "source": [] 1067 | } 1068 | ], 1069 | "metadata": { 1070 | "kernelspec": { 1071 | "display_name": "Python 3", 1072 | "language": "python", 1073 | "name": "python3" 1074 | }, 1075 | "language_info": { 1076 | "codemirror_mode": { 1077 | "name": "ipython", 1078 | "version": 3 1079 | }, 1080 | "file_extension": ".py", 1081 | "mimetype": "text/x-python", 1082 | "name": "python", 1083 | "nbconvert_exporter": "python", 1084 | "pygments_lexer": "ipython3", 1085 | "version": "3.7.4" 1086 | } 1087 | }, 1088 | "nbformat": 4, 1089 | "nbformat_minor": 2 1090 | } 1091 | -------------------------------------------------------------------------------- /Dictionaries & Sets In Python..ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Python Dictionaries\n", 8 | " Dictionary created with {}\n", 9 | " items in dictionaries are key-value based NOT on index base" 10 | ] 11 | }, 12 | { 13 | "cell_type": "code", 14 | "execution_count": 7, 15 | "metadata": {}, 16 | "outputs": [ 17 | { 18 | "data": { 19 | "text/plain": [ 20 | "dict" 21 | ] 22 | }, 23 | "execution_count": 7, 24 | "metadata": {}, 25 | "output_type": "execute_result" 26 | } 27 | ], 28 | "source": [ 29 | "#Creating an Empty Dictionary\n", 30 | "country_with_capitals ={}\n", 31 | "type(country_with_capitals)" 32 | ] 33 | }, 34 | { 35 | "cell_type": "code", 36 | "execution_count": 55, 37 | "metadata": {}, 38 | "outputs": [], 39 | "source": [ 40 | "# Creating dictionary with key-value pair\n", 41 | "country_with_capitals ={\n", 42 | " \"Pakistan\":\"Islamabad\",\n", 43 | " \"USA\": \"Washington DC\",\n", 44 | " \"Bangladesh\":\"Dhaka\",\n", 45 | " \"India\" :\"Mumbai\"\n", 46 | "}" 47 | ] 48 | }, 49 | { 50 | "cell_type": "code", 51 | "execution_count": 56, 52 | "metadata": {}, 53 | "outputs": [ 54 | { 55 | "name": "stdout", 56 | "output_type": "stream", 57 | "text": [ 58 | "{'Pakistan': 'Islamabad', 'USA': 'Washington DC', 'Bangladesh': 'Dhaka', 'India': 'Mumbai'}\n" 59 | ] 60 | } 61 | ], 62 | "source": [ 63 | "print(country_with_capitals)" 64 | ] 65 | }, 66 | { 67 | "cell_type": "code", 68 | "execution_count": 57, 69 | "metadata": {}, 70 | "outputs": [ 71 | { 72 | "data": { 73 | "text/plain": [ 74 | "4" 75 | ] 76 | }, 77 | "execution_count": 57, 78 | "metadata": {}, 79 | "output_type": "execute_result" 80 | } 81 | ], 82 | "source": [ 83 | "len(country_with_capitals)" 84 | ] 85 | }, 86 | { 87 | "cell_type": "code", 88 | "execution_count": 58, 89 | "metadata": {}, 90 | "outputs": [ 91 | { 92 | "name": "stdout", 93 | "output_type": "stream", 94 | "text": [ 95 | "{'Pakistan': 'Islamabad', 'USA': 'Washington DC', 'Bangladesh': 'Dhaka', 'India': 'Mumbai'}\n" 96 | ] 97 | } 98 | ], 99 | "source": [ 100 | "print(country_with_capitals)" 101 | ] 102 | }, 103 | { 104 | "cell_type": "code", 105 | "execution_count": 59, 106 | "metadata": {}, 107 | "outputs": [ 108 | { 109 | "data": { 110 | "text/plain": [ 111 | "'Islamabad'" 112 | ] 113 | }, 114 | "execution_count": 59, 115 | "metadata": {}, 116 | "output_type": "execute_result" 117 | } 118 | ], 119 | "source": [ 120 | "# retrival of data from all Data Structure\n", 121 | "# based on Keys only\n", 122 | "country_with_capitals[\"Pakistan\"]" 123 | ] 124 | }, 125 | { 126 | "cell_type": "markdown", 127 | "metadata": {}, 128 | "source": [ 129 | "# Dictionary Elements Deletion\n", 130 | " -Pop\n", 131 | " -del\n", 132 | " -pop items" 133 | ] 134 | }, 135 | { 136 | "cell_type": "code", 137 | "execution_count": 60, 138 | "metadata": {}, 139 | "outputs": [ 140 | { 141 | "data": { 142 | "text/plain": [ 143 | "'Dhaka'" 144 | ] 145 | }, 146 | "execution_count": 60, 147 | "metadata": {}, 148 | "output_type": "execute_result" 149 | } 150 | ], 151 | "source": [ 152 | "country_with_capitals.pop(\"Bangladesh\")" 153 | ] 154 | }, 155 | { 156 | "cell_type": "code", 157 | "execution_count": 61, 158 | "metadata": {}, 159 | "outputs": [], 160 | "source": [ 161 | "del country_with_capitals[\"India\"]" 162 | ] 163 | }, 164 | { 165 | "cell_type": "code", 166 | "execution_count": 54, 167 | "metadata": {}, 168 | "outputs": [ 169 | { 170 | "name": "stdout", 171 | "output_type": "stream", 172 | "text": [ 173 | "{'Pakistan': 'Islamabad', 'USA': 'Washington DC'}\n" 174 | ] 175 | } 176 | ], 177 | "source": [ 178 | "print(country_with_capitals)" 179 | ] 180 | }, 181 | { 182 | "cell_type": "code", 183 | "execution_count": 62, 184 | "metadata": {}, 185 | "outputs": [ 186 | { 187 | "name": "stdout", 188 | "output_type": "stream", 189 | "text": [ 190 | "('USA', 'Washington DC')\n", 191 | "{'Pakistan': 'Islamabad'}\n" 192 | ] 193 | } 194 | ], 195 | "source": [ 196 | "popitems=country_with_capitals.popitem()\n", 197 | "print(popitems)\n", 198 | "print(country_with_capitals)" 199 | ] 200 | }, 201 | { 202 | "cell_type": "code", 203 | "execution_count": 63, 204 | "metadata": {}, 205 | "outputs": [], 206 | "source": [ 207 | "country_with_capitals ['Iraq'] = 'Baghdad'" 208 | ] 209 | }, 210 | { 211 | "cell_type": "code", 212 | "execution_count": 64, 213 | "metadata": {}, 214 | "outputs": [ 215 | { 216 | "data": { 217 | "text/plain": [ 218 | "{'Pakistan': 'Islamabad', 'Iraq': 'Baghdad'}" 219 | ] 220 | }, 221 | "execution_count": 64, 222 | "metadata": {}, 223 | "output_type": "execute_result" 224 | } 225 | ], 226 | "source": [ 227 | "country_with_capitals" 228 | ] 229 | }, 230 | { 231 | "cell_type": "code", 232 | "execution_count": 90, 233 | "metadata": {}, 234 | "outputs": [ 235 | { 236 | "data": { 237 | "text/plain": [ 238 | "{1: 1, 2: 4, 4: 64, 5: 'Ahmed'}" 239 | ] 240 | }, 241 | "execution_count": 90, 242 | "metadata": {}, 243 | "output_type": "execute_result" 244 | } 245 | ], 246 | "source": [ 247 | "temp_dict = {1:1, 2:4, 4:64, 5:\"Ahmed\"}\n", 248 | "temp_dict" 249 | ] 250 | }, 251 | { 252 | "cell_type": "code", 253 | "execution_count": 91, 254 | "metadata": {}, 255 | "outputs": [ 256 | { 257 | "data": { 258 | "text/plain": [ 259 | "'Ahmed'" 260 | ] 261 | }, 262 | "execution_count": 91, 263 | "metadata": {}, 264 | "output_type": "execute_result" 265 | } 266 | ], 267 | "source": [ 268 | "temp_dict[5]" 269 | ] 270 | }, 271 | { 272 | "cell_type": "code", 273 | "execution_count": 92, 274 | "metadata": {}, 275 | "outputs": [ 276 | { 277 | "data": { 278 | "text/plain": [ 279 | "'h'" 280 | ] 281 | }, 282 | "execution_count": 92, 283 | "metadata": {}, 284 | "output_type": "execute_result" 285 | } 286 | ], 287 | "source": [ 288 | "temp_dict[5][1]" 289 | ] 290 | }, 291 | { 292 | "cell_type": "code", 293 | "execution_count": 77, 294 | "metadata": {}, 295 | "outputs": [], 296 | "source": [ 297 | "sales = {\n", 298 | " 'Item':[\"laptop\",\"Monitor\",\"Speaker\",\"Keyboard\",\"Mouse\",\"Handsfree\"],\n", 299 | " 'Price':[25000000,25000,32000,42000,950,2560],\n", 300 | " 'Units':[25,30,12,10,25,400],\n", 301 | " 'sales_man':[\"Ahmed\",\"Ali\",\"Ahsan\",\"Aslam\",\"Abbas\",\"Asim\"]\n", 302 | "}" 303 | ] 304 | }, 305 | { 306 | "cell_type": "code", 307 | "execution_count": 78, 308 | "metadata": {}, 309 | "outputs": [ 310 | { 311 | "data": { 312 | "text/plain": [ 313 | "{'Item': ['laptop', 'Monitor', 'Speaker', 'Keyboard', 'Mouse', 'Handsfree'],\n", 314 | " 'Price': [25000000, 25000, 32000, 42000, 950, 2560],\n", 315 | " 'Units': [25, 30, 12, 10, 25, 400],\n", 316 | " 'sales_man': ['Ahmed', 'Ali', 'Ahsan', 'Aslam', 'Abbas', 'Asim']}" 317 | ] 318 | }, 319 | "execution_count": 78, 320 | "metadata": {}, 321 | "output_type": "execute_result" 322 | } 323 | ], 324 | "source": [ 325 | "sales" 326 | ] 327 | }, 328 | { 329 | "cell_type": "code", 330 | "execution_count": 83, 331 | "metadata": {}, 332 | "outputs": [ 333 | { 334 | "data": { 335 | "text/html": [ 336 | "
\n", 337 | "\n", 350 | "\n", 351 | " \n", 352 | " \n", 353 | " \n", 354 | " \n", 355 | " \n", 356 | " \n", 357 | " \n", 358 | " \n", 359 | " \n", 360 | " \n", 361 | " \n", 362 | " \n", 363 | " \n", 364 | " \n", 365 | " \n", 366 | " \n", 367 | " \n", 368 | " \n", 369 | " \n", 370 | " \n", 371 | " \n", 372 | " \n", 373 | " \n", 374 | " \n", 375 | " \n", 376 | " \n", 377 | " \n", 378 | " \n", 379 | " \n", 380 | " \n", 381 | " \n", 382 | " \n", 383 | " \n", 384 | " \n", 385 | " \n", 386 | " \n", 387 | " \n", 388 | " \n", 389 | " \n", 390 | " \n", 391 | " \n", 392 | " \n", 393 | " \n", 394 | " \n", 395 | " \n", 396 | " \n", 397 | " \n", 398 | " \n", 399 | " \n", 400 | " \n", 401 | " \n", 402 | " \n", 403 | " \n", 404 | "
ItemPriceUnitssales_man
0laptop2500000025Ahmed
1Monitor2500030Ali
2Speaker3200012Ahsan
3Keyboard4200010Aslam
4Mouse95025Abbas
5Handsfree2560400Asim
\n", 405 | "
" 406 | ], 407 | "text/plain": [ 408 | " Item Price Units sales_man\n", 409 | "0 laptop 25000000 25 Ahmed\n", 410 | "1 Monitor 25000 30 Ali\n", 411 | "2 Speaker 32000 12 Ahsan\n", 412 | "3 Keyboard 42000 10 Aslam\n", 413 | "4 Mouse 950 25 Abbas\n", 414 | "5 Handsfree 2560 400 Asim" 415 | ] 416 | }, 417 | "execution_count": 83, 418 | "metadata": {}, 419 | "output_type": "execute_result" 420 | } 421 | ], 422 | "source": [ 423 | "import pandas as pd\n", 424 | "Shop=pd.DataFrame(sales)\n", 425 | "Shop" 426 | ] 427 | }, 428 | { 429 | "cell_type": "code", 430 | "execution_count": 98, 431 | "metadata": {}, 432 | "outputs": [ 433 | { 434 | "data": { 435 | "text/plain": [ 436 | "{'Item': ['laptop', 'Monitor', 'Speaker', 'Keyboard', 'Mouse', 'Handsfree'],\n", 437 | " 'Price': [25000000, 25000, 32000, 42000, 950, 2560],\n", 438 | " 'Units': [25, 30, 12, 10, 25, 400],\n", 439 | " 'sales_man': ['Ahmed', 'Ali', 'Ahsan', 'Aslam', 'Abbas', 'Asim']}" 440 | ] 441 | }, 442 | "execution_count": 98, 443 | "metadata": {}, 444 | "output_type": "execute_result" 445 | } 446 | ], 447 | "source": [ 448 | "sales" 449 | ] 450 | }, 451 | { 452 | "cell_type": "code", 453 | "execution_count": 105, 454 | "metadata": {}, 455 | "outputs": [ 456 | { 457 | "data": { 458 | "text/plain": [ 459 | "['laptop', 'Monitor', 'Speaker', 'Keyboard', 'Mouse', 'Handsfree']" 460 | ] 461 | }, 462 | "execution_count": 105, 463 | "metadata": {}, 464 | "output_type": "execute_result" 465 | } 466 | ], 467 | "source": [ 468 | "sales.get('Item')" 469 | ] 470 | }, 471 | { 472 | "cell_type": "code", 473 | "execution_count": 108, 474 | "metadata": {}, 475 | "outputs": [ 476 | { 477 | "data": { 478 | "text/plain": [ 479 | "dict_keys(['Item', 'Price', 'Units', 'sales_man'])" 480 | ] 481 | }, 482 | "execution_count": 108, 483 | "metadata": {}, 484 | "output_type": "execute_result" 485 | } 486 | ], 487 | "source": [ 488 | "sales.keys()" 489 | ] 490 | }, 491 | { 492 | "cell_type": "code", 493 | "execution_count": 109, 494 | "metadata": {}, 495 | "outputs": [ 496 | { 497 | "data": { 498 | "text/plain": [ 499 | "dict_values([['laptop', 'Monitor', 'Speaker', 'Keyboard', 'Mouse', 'Handsfree'], [25000000, 25000, 32000, 42000, 950, 2560], [25, 30, 12, 10, 25, 400], ['Ahmed', 'Ali', 'Ahsan', 'Aslam', 'Abbas', 'Asim']])" 500 | ] 501 | }, 502 | "execution_count": 109, 503 | "metadata": {}, 504 | "output_type": "execute_result" 505 | } 506 | ], 507 | "source": [ 508 | "sales.values()" 509 | ] 510 | }, 511 | { 512 | "cell_type": "code", 513 | "execution_count": 110, 514 | "metadata": {}, 515 | "outputs": [ 516 | { 517 | "data": { 518 | "text/plain": [ 519 | "dict_items([('Item', ['laptop', 'Monitor', 'Speaker', 'Keyboard', 'Mouse', 'Handsfree']), ('Price', [25000000, 25000, 32000, 42000, 950, 2560]), ('Units', [25, 30, 12, 10, 25, 400]), ('sales_man', ['Ahmed', 'Ali', 'Ahsan', 'Aslam', 'Abbas', 'Asim'])])" 520 | ] 521 | }, 522 | "execution_count": 110, 523 | "metadata": {}, 524 | "output_type": "execute_result" 525 | } 526 | ], 527 | "source": [ 528 | "sales.items()" 529 | ] 530 | }, 531 | { 532 | "cell_type": "code", 533 | "execution_count": 111, 534 | "metadata": {}, 535 | "outputs": [], 536 | "source": [ 537 | "# work likes Extend in list\n", 538 | "sales.update({\"Adress\" :\"Karachi\", \"contact\":\"02154564564\"})" 539 | ] 540 | }, 541 | { 542 | "cell_type": "code", 543 | "execution_count": 112, 544 | "metadata": {}, 545 | "outputs": [ 546 | { 547 | "data": { 548 | "text/plain": [ 549 | "{'Item': ['laptop', 'Monitor', 'Speaker', 'Keyboard', 'Mouse', 'Handsfree'],\n", 550 | " 'Price': [25000000, 25000, 32000, 42000, 950, 2560],\n", 551 | " 'Units': [25, 30, 12, 10, 25, 400],\n", 552 | " 'sales_man': ['Ahmed', 'Ali', 'Ahsan', 'Aslam', 'Abbas', 'Asim'],\n", 553 | " 'Adress': 'Karachi',\n", 554 | " 'contact': '02154564564'}" 555 | ] 556 | }, 557 | "execution_count": 112, 558 | "metadata": {}, 559 | "output_type": "execute_result" 560 | } 561 | ], 562 | "source": [ 563 | "sales" 564 | ] 565 | }, 566 | { 567 | "cell_type": "code", 568 | "execution_count": 113, 569 | "metadata": {}, 570 | "outputs": [ 571 | { 572 | "ename": "TypeError", 573 | "evalue": "unsupported operand type(s) for +: 'dict' and 'dict'", 574 | "output_type": "error", 575 | "traceback": [ 576 | "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", 577 | "\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)", 578 | "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mcountry_with_capitals\u001b[0m \u001b[1;33m+\u001b[0m \u001b[0mtemp_dict\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", 579 | "\u001b[1;31mTypeError\u001b[0m: unsupported operand type(s) for +: 'dict' and 'dict'" 580 | ] 581 | } 582 | ], 583 | "source": [ 584 | "# + Operator not works in dictionary to concatinate two dictionaries\n", 585 | "country_with_capitals + temp_dict" 586 | ] 587 | }, 588 | { 589 | "cell_type": "code", 590 | "execution_count": 121, 591 | "metadata": {}, 592 | "outputs": [ 593 | { 594 | "data": { 595 | "text/plain": [ 596 | "{'Pakistan': 'Islamabad', 'Iraq': 'Baghdad', 'iamdefault': None}" 597 | ] 598 | }, 599 | "execution_count": 121, 600 | "metadata": {}, 601 | "output_type": "execute_result" 602 | } 603 | ], 604 | "source": [ 605 | "country_with_capitals.setdefault('iamdefault')\n", 606 | "country_with_capitals" 607 | ] 608 | }, 609 | { 610 | "cell_type": "code", 611 | "execution_count": 122, 612 | "metadata": {}, 613 | "outputs": [ 614 | { 615 | "name": "stdout", 616 | "output_type": "stream", 617 | "text": [ 618 | "{'key1': None, 'key2': None, 'key3': None}\n" 619 | ] 620 | } 621 | ], 622 | "source": [ 623 | "x = ('key1', 'key2', 'key3')\n", 624 | "\n", 625 | "thisdict = dict.fromkeys(x)\n", 626 | "\n", 627 | "print(thisdict)" 628 | ] 629 | }, 630 | { 631 | "cell_type": "code", 632 | "execution_count": 131, 633 | "metadata": {}, 634 | "outputs": [ 635 | { 636 | "name": "stdout", 637 | "output_type": "stream", 638 | "text": [ 639 | "{'Pakistan': 'Hello from Russia', 'Iraq': 'Hello from Russia', 'iamdefault': 'Hello from Russia'}\n" 640 | ] 641 | } 642 | ], 643 | "source": [ 644 | "x = country_with_capitals.keys()\n", 645 | "y = \"Hello from Russia\"\n", 646 | "\n", 647 | "thisdict = dict.fromkeys(x, y)\n", 648 | "\n", 649 | "print(thisdict)" 650 | ] 651 | }, 652 | { 653 | "cell_type": "code", 654 | "execution_count": 133, 655 | "metadata": {}, 656 | "outputs": [], 657 | "source": [ 658 | "d = dict(foo=100,boo=200)" 659 | ] 660 | }, 661 | { 662 | "cell_type": "code", 663 | "execution_count": 134, 664 | "metadata": {}, 665 | "outputs": [ 666 | { 667 | "data": { 668 | "text/plain": [ 669 | "dict" 670 | ] 671 | }, 672 | "execution_count": 134, 673 | "metadata": {}, 674 | "output_type": "execute_result" 675 | } 676 | ], 677 | "source": [ 678 | "type(d)" 679 | ] 680 | }, 681 | { 682 | "cell_type": "code", 683 | "execution_count": 137, 684 | "metadata": {}, 685 | "outputs": [], 686 | "source": [ 687 | "d = dict([\n", 688 | " ('foo',100),\n", 689 | " ('boo',200)\n", 690 | "])" 691 | ] 692 | }, 693 | { 694 | "cell_type": "code", 695 | "execution_count": 138, 696 | "metadata": {}, 697 | "outputs": [ 698 | { 699 | "data": { 700 | "text/plain": [ 701 | "dict" 702 | ] 703 | }, 704 | "execution_count": 138, 705 | "metadata": {}, 706 | "output_type": "execute_result" 707 | } 708 | ], 709 | "source": [ 710 | "type(d)" 711 | ] 712 | }, 713 | { 714 | "cell_type": "code", 715 | "execution_count": 144, 716 | "metadata": {}, 717 | "outputs": [], 718 | "source": [ 719 | "d = {\n", 720 | " ('foo',100),\n", 721 | " ('boo',200)\n", 722 | "}" 723 | ] 724 | }, 725 | { 726 | "cell_type": "code", 727 | "execution_count": 145, 728 | "metadata": {}, 729 | "outputs": [ 730 | { 731 | "data": { 732 | "text/plain": [ 733 | "set" 734 | ] 735 | }, 736 | "execution_count": 145, 737 | "metadata": {}, 738 | "output_type": "execute_result" 739 | } 740 | ], 741 | "source": [ 742 | "type(d)" 743 | ] 744 | }, 745 | { 746 | "cell_type": "code", 747 | "execution_count": 146, 748 | "metadata": {}, 749 | "outputs": [ 750 | { 751 | "data": { 752 | "text/plain": [ 753 | "['a', 'b', {'foo': 1, 'bar': {'x': 10, 'y': 20, 'z': 30}, 'baz': 3}, 'c', 'd']" 754 | ] 755 | }, 756 | "execution_count": 146, 757 | "metadata": {}, 758 | "output_type": "execute_result" 759 | } 760 | ], 761 | "source": [ 762 | "x=['a','b',{'foo':1,'bar':{'x':10,'y':20,'z':30},'baz':3},'c','d']\n", 763 | "x" 764 | ] 765 | }, 766 | { 767 | "cell_type": "code", 768 | "execution_count": 148, 769 | "metadata": {}, 770 | "outputs": [ 771 | { 772 | "data": { 773 | "text/plain": [ 774 | "30" 775 | ] 776 | }, 777 | "execution_count": 148, 778 | "metadata": {}, 779 | "output_type": "execute_result" 780 | } 781 | ], 782 | "source": [ 783 | "x[2]['bar']['z']" 784 | ] 785 | }, 786 | { 787 | "cell_type": "code", 788 | "execution_count": 152, 789 | "metadata": {}, 790 | "outputs": [ 791 | { 792 | "data": { 793 | "text/plain": [ 794 | "{(3+2j): 'Imaginary Number'}" 795 | ] 796 | }, 797 | "execution_count": 152, 798 | "metadata": {}, 799 | "output_type": "execute_result" 800 | } 801 | ], 802 | "source": [ 803 | "{(3+2j):\"Imaginary Number\"}" 804 | ] 805 | }, 806 | { 807 | "cell_type": "code", 808 | "execution_count": 153, 809 | "metadata": {}, 810 | "outputs": [ 811 | { 812 | "data": { 813 | "text/plain": [ 814 | "{: 23}" 815 | ] 816 | }, 817 | "execution_count": 153, 818 | "metadata": {}, 819 | "output_type": "execute_result" 820 | } 821 | ], 822 | "source": [ 823 | "{len:23}" 824 | ] 825 | }, 826 | { 827 | "cell_type": "code", 828 | "execution_count": 154, 829 | "metadata": {}, 830 | "outputs": [ 831 | { 832 | "ename": "SyntaxError", 833 | "evalue": "keyword can't be an expression (, line 1)", 834 | "output_type": "error", 835 | "traceback": [ 836 | "\u001b[1;36m File \u001b[1;32m\"\"\u001b[1;36m, line \u001b[1;32m1\u001b[0m\n\u001b[1;33m {dict('foo'=1,\"bar\"=3):\"Number\"}\u001b[0m\n\u001b[1;37m ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m keyword can't be an expression\n" 837 | ] 838 | } 839 | ], 840 | "source": [ 841 | "{dict('foo'=1,\"bar\"=3):\"Number\"}" 842 | ] 843 | }, 844 | { 845 | "cell_type": "code", 846 | "execution_count": 155, 847 | "metadata": {}, 848 | "outputs": [ 849 | { 850 | "data": { 851 | "text/plain": [ 852 | "{(1, 2): 'a'}" 853 | ] 854 | }, 855 | "execution_count": 155, 856 | "metadata": {}, 857 | "output_type": "execute_result" 858 | } 859 | ], 860 | "source": [ 861 | "{(1,2):\"a\"}" 862 | ] 863 | }, 864 | { 865 | "cell_type": "code", 866 | "execution_count": 156, 867 | "metadata": {}, 868 | "outputs": [ 869 | { 870 | "data": { 871 | "text/plain": [ 872 | "False" 873 | ] 874 | }, 875 | "execution_count": 156, 876 | "metadata": {}, 877 | "output_type": "execute_result" 878 | } 879 | ], 880 | "source": [ 881 | "x=['a','b',{'foo':1,'bar':{'x':10,'y':20,'z':30},'baz':3},'c','d']\n", 882 | "'z' in [2]" 883 | ] 884 | }, 885 | { 886 | "cell_type": "markdown", 887 | "metadata": {}, 888 | "source": [ 889 | "# Set In Python" 890 | ] 891 | }, 892 | { 893 | "cell_type": "code", 894 | "execution_count": 179, 895 | "metadata": {}, 896 | "outputs": [ 897 | { 898 | "data": { 899 | "text/plain": [ 900 | "set" 901 | ] 902 | }, 903 | "execution_count": 179, 904 | "metadata": {}, 905 | "output_type": "execute_result" 906 | } 907 | ], 908 | "source": [ 909 | "aset = {1, 2, 3, 4, 5, 6, 7, 8, 9 ,10,10, 11, 12, 13, 14, 15, 16, 17, 18, 19,\n", 910 | "20, 21, 22, 23, 24, 25, 26, 27, 28, 29,\n", 911 | "30, 31, 32, 33, 34, 35, 36, 37, 38, 39,\n", 912 | "40, 41, 42, 43, 44, 45, 46, 47, 48, 49,\n", 913 | "50}\n", 914 | "type(aset)" 915 | ] 916 | }, 917 | { 918 | "cell_type": "code", 919 | "execution_count": 180, 920 | "metadata": {}, 921 | "outputs": [ 922 | { 923 | "data": { 924 | "text/plain": [ 925 | "{1,\n", 926 | " 2,\n", 927 | " 3,\n", 928 | " 4,\n", 929 | " 5,\n", 930 | " 6,\n", 931 | " 7,\n", 932 | " 8,\n", 933 | " 9,\n", 934 | " 10,\n", 935 | " 11,\n", 936 | " 12,\n", 937 | " 13,\n", 938 | " 14,\n", 939 | " 15,\n", 940 | " 16,\n", 941 | " 17,\n", 942 | " 18,\n", 943 | " 19,\n", 944 | " 20,\n", 945 | " 21,\n", 946 | " 22,\n", 947 | " 23,\n", 948 | " 24,\n", 949 | " 25,\n", 950 | " 26,\n", 951 | " 27,\n", 952 | " 28,\n", 953 | " 29,\n", 954 | " 30,\n", 955 | " 31,\n", 956 | " 32,\n", 957 | " 33,\n", 958 | " 34,\n", 959 | " 35,\n", 960 | " 36,\n", 961 | " 37,\n", 962 | " 38,\n", 963 | " 39,\n", 964 | " 40,\n", 965 | " 41,\n", 966 | " 42,\n", 967 | " 43,\n", 968 | " 44,\n", 969 | " 45,\n", 970 | " 46,\n", 971 | " 47,\n", 972 | " 48,\n", 973 | " 49,\n", 974 | " 50}" 975 | ] 976 | }, 977 | "execution_count": 180, 978 | "metadata": {}, 979 | "output_type": "execute_result" 980 | } 981 | ], 982 | "source": [ 983 | "aset" 984 | ] 985 | }, 986 | { 987 | "cell_type": "code", 988 | "execution_count": 181, 989 | "metadata": {}, 990 | "outputs": [ 991 | { 992 | "data": { 993 | "text/plain": [ 994 | "dict" 995 | ] 996 | }, 997 | "execution_count": 181, 998 | "metadata": {}, 999 | "output_type": "execute_result" 1000 | } 1001 | ], 1002 | "source": [ 1003 | "bset= {}\n", 1004 | "type(bset)" 1005 | ] 1006 | }, 1007 | { 1008 | "cell_type": "code", 1009 | "execution_count": 182, 1010 | "metadata": {}, 1011 | "outputs": [], 1012 | "source": [ 1013 | "cset={1,\n", 1014 | " 2,\n", 1015 | " 3,\n", 1016 | " 4,\n", 1017 | " 5,\n", 1018 | " 6,\n", 1019 | " 7,\n", 1020 | " 8,\n", 1021 | " 9,\n", 1022 | " 10,\n", 1023 | " 11,\n", 1024 | " 12,\n", 1025 | " 13,\n", 1026 | " 14,\n", 1027 | " 15,\n", 1028 | " 16,\n", 1029 | " 17,\n", 1030 | " 18,\n", 1031 | " 19,\n", 1032 | " 20,\n", 1033 | " 21,\n", 1034 | " 22,\n", 1035 | " 23,\n", 1036 | " 24,\n", 1037 | " 25,\n", 1038 | " 26,\n", 1039 | " 27,\n", 1040 | " 28,\n", 1041 | " 29,\n", 1042 | " 30,}" 1043 | ] 1044 | }, 1045 | { 1046 | "cell_type": "code", 1047 | "execution_count": 183, 1048 | "metadata": {}, 1049 | "outputs": [ 1050 | { 1051 | "data": { 1052 | "text/plain": [ 1053 | "{1,\n", 1054 | " 2,\n", 1055 | " 3,\n", 1056 | " 4,\n", 1057 | " 5,\n", 1058 | " 6,\n", 1059 | " 7,\n", 1060 | " 8,\n", 1061 | " 9,\n", 1062 | " 10,\n", 1063 | " 11,\n", 1064 | " 12,\n", 1065 | " 13,\n", 1066 | " 14,\n", 1067 | " 15,\n", 1068 | " 16,\n", 1069 | " 17,\n", 1070 | " 18,\n", 1071 | " 19,\n", 1072 | " 20,\n", 1073 | " 21,\n", 1074 | " 22,\n", 1075 | " 23,\n", 1076 | " 24,\n", 1077 | " 25,\n", 1078 | " 26,\n", 1079 | " 27,\n", 1080 | " 28,\n", 1081 | " 29,\n", 1082 | " 30}" 1083 | ] 1084 | }, 1085 | "execution_count": 183, 1086 | "metadata": {}, 1087 | "output_type": "execute_result" 1088 | } 1089 | ], 1090 | "source": [ 1091 | "cset" 1092 | ] 1093 | }, 1094 | { 1095 | "cell_type": "code", 1096 | "execution_count": 184, 1097 | "metadata": {}, 1098 | "outputs": [ 1099 | { 1100 | "data": { 1101 | "text/plain": [ 1102 | "{31,\n", 1103 | " 32,\n", 1104 | " 33,\n", 1105 | " 34,\n", 1106 | " 35,\n", 1107 | " 36,\n", 1108 | " 37,\n", 1109 | " 38,\n", 1110 | " 39,\n", 1111 | " 40,\n", 1112 | " 41,\n", 1113 | " 42,\n", 1114 | " 43,\n", 1115 | " 44,\n", 1116 | " 45,\n", 1117 | " 46,\n", 1118 | " 47,\n", 1119 | " 48,\n", 1120 | " 49,\n", 1121 | " 50}" 1122 | ] 1123 | }, 1124 | "execution_count": 184, 1125 | "metadata": {}, 1126 | "output_type": "execute_result" 1127 | } 1128 | ], 1129 | "source": [ 1130 | "aset.difference(cset)" 1131 | ] 1132 | }, 1133 | { 1134 | "cell_type": "code", 1135 | "execution_count": 185, 1136 | "metadata": {}, 1137 | "outputs": [ 1138 | { 1139 | "data": { 1140 | "text/plain": [ 1141 | "{1,\n", 1142 | " 2,\n", 1143 | " 3,\n", 1144 | " 4,\n", 1145 | " 5,\n", 1146 | " 6,\n", 1147 | " 7,\n", 1148 | " 8,\n", 1149 | " 9,\n", 1150 | " 10,\n", 1151 | " 11,\n", 1152 | " 12,\n", 1153 | " 13,\n", 1154 | " 14,\n", 1155 | " 15,\n", 1156 | " 16,\n", 1157 | " 17,\n", 1158 | " 18,\n", 1159 | " 19,\n", 1160 | " 20,\n", 1161 | " 21,\n", 1162 | " 22,\n", 1163 | " 23,\n", 1164 | " 24,\n", 1165 | " 25,\n", 1166 | " 26,\n", 1167 | " 27,\n", 1168 | " 28,\n", 1169 | " 29,\n", 1170 | " 30}" 1171 | ] 1172 | }, 1173 | "execution_count": 185, 1174 | "metadata": {}, 1175 | "output_type": "execute_result" 1176 | } 1177 | ], 1178 | "source": [ 1179 | "aset.intersection(cset)" 1180 | ] 1181 | }, 1182 | { 1183 | "cell_type": "code", 1184 | "execution_count": 186, 1185 | "metadata": {}, 1186 | "outputs": [ 1187 | { 1188 | "data": { 1189 | "text/plain": [ 1190 | "False" 1191 | ] 1192 | }, 1193 | "execution_count": 186, 1194 | "metadata": {}, 1195 | "output_type": "execute_result" 1196 | } 1197 | ], 1198 | "source": [ 1199 | "aset.issubset(cset)" 1200 | ] 1201 | }, 1202 | { 1203 | "cell_type": "code", 1204 | "execution_count": 187, 1205 | "metadata": {}, 1206 | "outputs": [ 1207 | { 1208 | "data": { 1209 | "text/plain": [ 1210 | "True" 1211 | ] 1212 | }, 1213 | "execution_count": 187, 1214 | "metadata": {}, 1215 | "output_type": "execute_result" 1216 | } 1217 | ], 1218 | "source": [ 1219 | "cset.issubset(aset)" 1220 | ] 1221 | }, 1222 | { 1223 | "cell_type": "code", 1224 | "execution_count": 188, 1225 | "metadata": {}, 1226 | "outputs": [ 1227 | { 1228 | "data": { 1229 | "text/plain": [ 1230 | "True" 1231 | ] 1232 | }, 1233 | "execution_count": 188, 1234 | "metadata": {}, 1235 | "output_type": "execute_result" 1236 | } 1237 | ], 1238 | "source": [ 1239 | "aset.issuperset(cset)" 1240 | ] 1241 | }, 1242 | { 1243 | "cell_type": "code", 1244 | "execution_count": 191, 1245 | "metadata": {}, 1246 | "outputs": [], 1247 | "source": [ 1248 | "aset.add(100)" 1249 | ] 1250 | }, 1251 | { 1252 | "cell_type": "code", 1253 | "execution_count": 194, 1254 | "metadata": {}, 1255 | "outputs": [], 1256 | "source": [ 1257 | "aset.remove(101)" 1258 | ] 1259 | }, 1260 | { 1261 | "cell_type": "code", 1262 | "execution_count": 195, 1263 | "metadata": {}, 1264 | "outputs": [ 1265 | { 1266 | "data": { 1267 | "text/plain": [ 1268 | "{1,\n", 1269 | " 2,\n", 1270 | " 3,\n", 1271 | " 4,\n", 1272 | " 5,\n", 1273 | " 6,\n", 1274 | " 7,\n", 1275 | " 8,\n", 1276 | " 9,\n", 1277 | " 10,\n", 1278 | " 11,\n", 1279 | " 12,\n", 1280 | " 13,\n", 1281 | " 14,\n", 1282 | " 15,\n", 1283 | " 16,\n", 1284 | " 17,\n", 1285 | " 18,\n", 1286 | " 19,\n", 1287 | " 20,\n", 1288 | " 21,\n", 1289 | " 22,\n", 1290 | " 23,\n", 1291 | " 24,\n", 1292 | " 25,\n", 1293 | " 26,\n", 1294 | " 27,\n", 1295 | " 28,\n", 1296 | " 29,\n", 1297 | " 30,\n", 1298 | " 31,\n", 1299 | " 32,\n", 1300 | " 33,\n", 1301 | " 34,\n", 1302 | " 35,\n", 1303 | " 36,\n", 1304 | " 37,\n", 1305 | " 38,\n", 1306 | " 39,\n", 1307 | " 40,\n", 1308 | " 41,\n", 1309 | " 42,\n", 1310 | " 43,\n", 1311 | " 44,\n", 1312 | " 45,\n", 1313 | " 46,\n", 1314 | " 47,\n", 1315 | " 48,\n", 1316 | " 49,\n", 1317 | " 50,\n", 1318 | " 100}" 1319 | ] 1320 | }, 1321 | "execution_count": 195, 1322 | "metadata": {}, 1323 | "output_type": "execute_result" 1324 | } 1325 | ], 1326 | "source": [ 1327 | "aset" 1328 | ] 1329 | }, 1330 | { 1331 | "cell_type": "code", 1332 | "execution_count": 196, 1333 | "metadata": {}, 1334 | "outputs": [ 1335 | { 1336 | "data": { 1337 | "text/plain": [ 1338 | "False" 1339 | ] 1340 | }, 1341 | "execution_count": 196, 1342 | "metadata": {}, 1343 | "output_type": "execute_result" 1344 | } 1345 | ], 1346 | "source": [ 1347 | "aset.isdisjoint(cset)" 1348 | ] 1349 | }, 1350 | { 1351 | "cell_type": "code", 1352 | "execution_count": 197, 1353 | "metadata": {}, 1354 | "outputs": [ 1355 | { 1356 | "data": { 1357 | "text/plain": [ 1358 | "{1,\n", 1359 | " 2,\n", 1360 | " 3,\n", 1361 | " 4,\n", 1362 | " 5,\n", 1363 | " 6,\n", 1364 | " 7,\n", 1365 | " 8,\n", 1366 | " 9,\n", 1367 | " 10,\n", 1368 | " 11,\n", 1369 | " 12,\n", 1370 | " 13,\n", 1371 | " 14,\n", 1372 | " 15,\n", 1373 | " 16,\n", 1374 | " 17,\n", 1375 | " 18,\n", 1376 | " 19,\n", 1377 | " 20,\n", 1378 | " 21,\n", 1379 | " 22,\n", 1380 | " 23,\n", 1381 | " 24,\n", 1382 | " 25,\n", 1383 | " 26,\n", 1384 | " 27,\n", 1385 | " 28,\n", 1386 | " 29,\n", 1387 | " 30,\n", 1388 | " 31,\n", 1389 | " 32,\n", 1390 | " 33,\n", 1391 | " 34,\n", 1392 | " 35,\n", 1393 | " 36,\n", 1394 | " 37,\n", 1395 | " 38,\n", 1396 | " 39,\n", 1397 | " 40,\n", 1398 | " 41,\n", 1399 | " 42,\n", 1400 | " 43,\n", 1401 | " 44,\n", 1402 | " 45,\n", 1403 | " 46,\n", 1404 | " 47,\n", 1405 | " 48,\n", 1406 | " 49,\n", 1407 | " 50,\n", 1408 | " 100}" 1409 | ] 1410 | }, 1411 | "execution_count": 197, 1412 | "metadata": {}, 1413 | "output_type": "execute_result" 1414 | } 1415 | ], 1416 | "source": [ 1417 | "aset.union(cset)" 1418 | ] 1419 | }, 1420 | { 1421 | "cell_type": "code", 1422 | "execution_count": 198, 1423 | "metadata": {}, 1424 | "outputs": [ 1425 | { 1426 | "data": { 1427 | "text/plain": [ 1428 | "{31,\n", 1429 | " 32,\n", 1430 | " 33,\n", 1431 | " 34,\n", 1432 | " 35,\n", 1433 | " 36,\n", 1434 | " 37,\n", 1435 | " 38,\n", 1436 | " 39,\n", 1437 | " 40,\n", 1438 | " 41,\n", 1439 | " 42,\n", 1440 | " 43,\n", 1441 | " 44,\n", 1442 | " 45,\n", 1443 | " 46,\n", 1444 | " 47,\n", 1445 | " 48,\n", 1446 | " 49,\n", 1447 | " 50,\n", 1448 | " 100}" 1449 | ] 1450 | }, 1451 | "execution_count": 198, 1452 | "metadata": {}, 1453 | "output_type": "execute_result" 1454 | } 1455 | ], 1456 | "source": [ 1457 | "aset.symmetric_difference(cset)" 1458 | ] 1459 | }, 1460 | { 1461 | "cell_type": "code", 1462 | "execution_count": 199, 1463 | "metadata": {}, 1464 | "outputs": [ 1465 | { 1466 | "data": { 1467 | "text/plain": [ 1468 | "{31,\n", 1469 | " 32,\n", 1470 | " 33,\n", 1471 | " 34,\n", 1472 | " 35,\n", 1473 | " 36,\n", 1474 | " 37,\n", 1475 | " 38,\n", 1476 | " 39,\n", 1477 | " 40,\n", 1478 | " 41,\n", 1479 | " 42,\n", 1480 | " 43,\n", 1481 | " 44,\n", 1482 | " 45,\n", 1483 | " 46,\n", 1484 | " 47,\n", 1485 | " 48,\n", 1486 | " 49,\n", 1487 | " 50,\n", 1488 | " 100}" 1489 | ] 1490 | }, 1491 | "execution_count": 199, 1492 | "metadata": {}, 1493 | "output_type": "execute_result" 1494 | } 1495 | ], 1496 | "source": [ 1497 | "aset.difference(cset)" 1498 | ] 1499 | }, 1500 | { 1501 | "cell_type": "code", 1502 | "execution_count": 203, 1503 | "metadata": {}, 1504 | "outputs": [ 1505 | { 1506 | "name": "stdout", 1507 | "output_type": "stream", 1508 | "text": [ 1509 | "{'apple'}\n" 1510 | ] 1511 | } 1512 | ], 1513 | "source": [ 1514 | "x = {\"apple\", \"banana\", \"cherry\"}\n", 1515 | "y = {\"google\", \"microsoft\", \"apple\"}\n", 1516 | "\n", 1517 | "x.intersection_update(y)\n", 1518 | "\n", 1519 | "print(x)" 1520 | ] 1521 | }, 1522 | { 1523 | "cell_type": "code", 1524 | "execution_count": 209, 1525 | "metadata": {}, 1526 | "outputs": [ 1527 | { 1528 | "data": { 1529 | "text/plain": [ 1530 | "{'banana', 'cherry'}" 1531 | ] 1532 | }, 1533 | "execution_count": 209, 1534 | "metadata": {}, 1535 | "output_type": "execute_result" 1536 | } 1537 | ], 1538 | "source": [ 1539 | "x = {\"apple\", \"banana\", \"cherry\"}\n", 1540 | "y = {\"google\", \"microsoft\", \"apple\"}\n", 1541 | "\n", 1542 | "x.difference(y)\n" 1543 | ] 1544 | }, 1545 | { 1546 | "cell_type": "code", 1547 | "execution_count": 212, 1548 | "metadata": {}, 1549 | "outputs": [ 1550 | { 1551 | "name": "stdout", 1552 | "output_type": "stream", 1553 | "text": [ 1554 | "{'banana', 'cherry'}\n" 1555 | ] 1556 | } 1557 | ], 1558 | "source": [ 1559 | "x = {\"apple\", \"banana\", \"cherry\"}\n", 1560 | "y = {\"google\", \"microsoft\", \"apple\"}\n", 1561 | "\n", 1562 | "x.difference_update(y)\n", 1563 | "\n", 1564 | "print(x)" 1565 | ] 1566 | }, 1567 | { 1568 | "cell_type": "code", 1569 | "execution_count": 206, 1570 | "metadata": {}, 1571 | "outputs": [ 1572 | { 1573 | "name": "stdout", 1574 | "output_type": "stream", 1575 | "text": [ 1576 | "{'banana', 'apple', 'cherry'}\n" 1577 | ] 1578 | } 1579 | ], 1580 | "source": [ 1581 | "x = {\"apple\", \"banana\", \"cherry\"}\n", 1582 | "y = {\"google\", \"microsoft\", \"apple\"}\n", 1583 | "\n", 1584 | "x.discard(y)\n", 1585 | "\n", 1586 | "print(x)" 1587 | ] 1588 | }, 1589 | { 1590 | "cell_type": "code", 1591 | "execution_count": null, 1592 | "metadata": {}, 1593 | "outputs": [], 1594 | "source": [] 1595 | } 1596 | ], 1597 | "metadata": { 1598 | "kernelspec": { 1599 | "display_name": "Python 3", 1600 | "language": "python", 1601 | "name": "python3" 1602 | }, 1603 | "language_info": { 1604 | "codemirror_mode": { 1605 | "name": "ipython", 1606 | "version": 3 1607 | }, 1608 | "file_extension": ".py", 1609 | "mimetype": "text/x-python", 1610 | "name": "python", 1611 | "nbconvert_exporter": "python", 1612 | "pygments_lexer": "ipython3", 1613 | "version": "3.7.4" 1614 | } 1615 | }, 1616 | "nbformat": 4, 1617 | "nbformat_minor": 2 1618 | } 1619 | -------------------------------------------------------------------------------- /List In Python.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# More on User Input ....." 8 | ] 9 | }, 10 | { 11 | "cell_type": "code", 12 | "execution_count": 4, 13 | "metadata": {}, 14 | "outputs": [ 15 | { 16 | "name": "stdout", 17 | "output_type": "stream", 18 | "text": [ 19 | "Enter your Favourite Number: 10\n" 20 | ] 21 | } 22 | ], 23 | "source": [ 24 | "favourite_number = input(\"Enter your Favourite Number: \" )" 25 | ] 26 | }, 27 | { 28 | "cell_type": "code", 29 | "execution_count": 5, 30 | "metadata": {}, 31 | "outputs": [ 32 | { 33 | "data": { 34 | "text/plain": [ 35 | "str" 36 | ] 37 | }, 38 | "execution_count": 5, 39 | "metadata": {}, 40 | "output_type": "execute_result" 41 | } 42 | ], 43 | "source": [ 44 | "type(favourite_number)" 45 | ] 46 | }, 47 | { 48 | "cell_type": "code", 49 | "execution_count": 7, 50 | "metadata": {}, 51 | "outputs": [ 52 | { 53 | "name": "stdout", 54 | "output_type": "stream", 55 | "text": [ 56 | "Enter your Favourite Number: 10\n" 57 | ] 58 | }, 59 | { 60 | "data": { 61 | "text/plain": [ 62 | "int" 63 | ] 64 | }, 65 | "execution_count": 7, 66 | "metadata": {}, 67 | "output_type": "execute_result" 68 | } 69 | ], 70 | "source": [ 71 | "favourite_number = int(input(\"Enter your Favourite Number: \" ))\n", 72 | "type(favourite_number)" 73 | ] 74 | }, 75 | { 76 | "cell_type": "code", 77 | "execution_count": 8, 78 | "metadata": {}, 79 | "outputs": [ 80 | { 81 | "data": { 82 | "text/plain": [ 83 | "123" 84 | ] 85 | }, 86 | "execution_count": 8, 87 | "metadata": {}, 88 | "output_type": "execute_result" 89 | } 90 | ], 91 | "source": [ 92 | "int(\"123\")" 93 | ] 94 | }, 95 | { 96 | "cell_type": "code", 97 | "execution_count": 10, 98 | "metadata": {}, 99 | "outputs": [ 100 | { 101 | "ename": "ValueError", 102 | "evalue": "invalid literal for int() with base 10: '123.8'", 103 | "output_type": "error", 104 | "traceback": [ 105 | "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", 106 | "\u001b[1;31mValueError\u001b[0m Traceback (most recent call last)", 107 | "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"123.8\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", 108 | "\u001b[1;31mValueError\u001b[0m: invalid literal for int() with base 10: '123.8'" 109 | ] 110 | } 111 | ], 112 | "source": [ 113 | "int(\"123.8\")" 114 | ] 115 | }, 116 | { 117 | "cell_type": "markdown", 118 | "metadata": {}, 119 | "source": [ 120 | "# Python Data Strucuture\n", 121 | "\n", 122 | " -list\n", 123 | " -Tuple\n", 124 | " -Set \n", 125 | " -Dictionary" 126 | ] 127 | }, 128 | { 129 | "cell_type": "code", 130 | "execution_count": 12, 131 | "metadata": {}, 132 | "outputs": [ 133 | { 134 | "name": "stdout", 135 | "output_type": "stream", 136 | "text": [ 137 | "['Apple', 'Mango', 'Cherry', 'Banana']\n", 138 | "\n" 139 | ] 140 | } 141 | ], 142 | "source": [ 143 | "fruits = ['Apple','Mango','Cherry','Banana']\n", 144 | "print(fruits)\n", 145 | "print(type(fruits))" 146 | ] 147 | }, 148 | { 149 | "cell_type": "code", 150 | "execution_count": null, 151 | "metadata": {}, 152 | "outputs": [], 153 | "source": [ 154 | "# index 0 1 2 3\n", 155 | "fruits = ['Apple','Mango','Cherry','Banana']\n", 156 | "# -veindex -4 -3 -2 -1\n", 157 | "\n", 158 | "# Operation on List \n", 159 | "\n", 160 | "# Crud (Operation)\n", 161 | "# Create\n", 162 | "# Retrive\n", 163 | "# Update\n", 164 | "# Delete\n", 165 | "# Slice" 166 | ] 167 | }, 168 | { 169 | "cell_type": "code", 170 | "execution_count": 17, 171 | "metadata": {}, 172 | "outputs": [ 173 | { 174 | "name": "stdout", 175 | "output_type": "stream", 176 | "text": [ 177 | "['Pakistan', 'India', 'Bangladesh', 'Srilanka', 'Canada', 'USA']\n" 178 | ] 179 | } 180 | ], 181 | "source": [ 182 | "country_List =[\"Pakistan\",\"India\",\"Bangladesh\",\"Srilanka\",\"Canada\",\"USA\"]\n", 183 | "print(country_List)" 184 | ] 185 | }, 186 | { 187 | "cell_type": "code", 188 | "execution_count": 19, 189 | "metadata": {}, 190 | "outputs": [ 191 | { 192 | "name": "stdout", 193 | "output_type": "stream", 194 | "text": [ 195 | "6\n" 196 | ] 197 | } 198 | ], 199 | "source": [ 200 | "print(len(country_List))" 201 | ] 202 | }, 203 | { 204 | "cell_type": "code", 205 | "execution_count": 21, 206 | "metadata": {}, 207 | "outputs": [ 208 | { 209 | "name": "stdout", 210 | "output_type": "stream", 211 | "text": [ 212 | "Pakistan\n" 213 | ] 214 | } 215 | ], 216 | "source": [ 217 | "print(country_List[0])" 218 | ] 219 | }, 220 | { 221 | "cell_type": "code", 222 | "execution_count": 24, 223 | "metadata": {}, 224 | "outputs": [ 225 | { 226 | "name": "stdout", 227 | "output_type": "stream", 228 | "text": [ 229 | "['Pakistan', 'India', 'Bangladesh', 'Srilanka', 'Canada']\n" 230 | ] 231 | } 232 | ], 233 | "source": [ 234 | "print(country_List[0 : 5])" 235 | ] 236 | }, 237 | { 238 | "cell_type": "code", 239 | "execution_count": 23, 240 | "metadata": {}, 241 | "outputs": [ 242 | { 243 | "name": "stdout", 244 | "output_type": "stream", 245 | "text": [ 246 | "Bangladesh\n" 247 | ] 248 | } 249 | ], 250 | "source": [ 251 | "print(country_List[-4])" 252 | ] 253 | }, 254 | { 255 | "cell_type": "code", 256 | "execution_count": 25, 257 | "metadata": {}, 258 | "outputs": [ 259 | { 260 | "name": "stdout", 261 | "output_type": "stream", 262 | "text": [ 263 | "['Pakistan', 'India', 'Bangladesh', 'Srilanka', 'Canada', 'USA']\n" 264 | ] 265 | } 266 | ], 267 | "source": [ 268 | "print(country_List[0:])" 269 | ] 270 | }, 271 | { 272 | "cell_type": "code", 273 | "execution_count": 26, 274 | "metadata": {}, 275 | "outputs": [ 276 | { 277 | "name": "stdout", 278 | "output_type": "stream", 279 | "text": [ 280 | "['Bangladesh', 'Srilanka', 'Canada', 'USA']\n" 281 | ] 282 | } 283 | ], 284 | "source": [ 285 | "print(country_List[2:6])" 286 | ] 287 | }, 288 | { 289 | "cell_type": "code", 290 | "execution_count": 27, 291 | "metadata": {}, 292 | "outputs": [ 293 | { 294 | "name": "stdout", 295 | "output_type": "stream", 296 | "text": [ 297 | "['Pakistan', 'India', 'Bangladesh', 'Srilanka', 'Canada', 'USA']\n" 298 | ] 299 | } 300 | ], 301 | "source": [ 302 | "print(country_List[:6])" 303 | ] 304 | }, 305 | { 306 | "cell_type": "code", 307 | "execution_count": 28, 308 | "metadata": {}, 309 | "outputs": [ 310 | { 311 | "name": "stdout", 312 | "output_type": "stream", 313 | "text": [ 314 | "['Pakistan', 'India', 'Bangladesh']\n" 315 | ] 316 | } 317 | ], 318 | "source": [ 319 | "print(country_List[0:-3])" 320 | ] 321 | }, 322 | { 323 | "cell_type": "code", 324 | "execution_count": 34, 325 | "metadata": {}, 326 | "outputs": [ 327 | { 328 | "name": "stdout", 329 | "output_type": "stream", 330 | "text": [ 331 | "['Pakistan', 'UK', 'Bangladesh', 'Srilanka', 'Canada', 'USA']\n" 332 | ] 333 | } 334 | ], 335 | "source": [ 336 | "country_List[1] = \"UK\"\n", 337 | "country_List[2] = \"Bangladesh\"\n", 338 | "print(country_List)" 339 | ] 340 | }, 341 | { 342 | "cell_type": "code", 343 | "execution_count": null, 344 | "metadata": {}, 345 | "outputs": [], 346 | "source": [ 347 | "# Adding more item in existing List\n", 348 | "# append\n", 349 | "# insert\n", 350 | "# +\n", 351 | "# extend" 352 | ] 353 | }, 354 | { 355 | "cell_type": "code", 356 | "execution_count": 35, 357 | "metadata": {}, 358 | "outputs": [], 359 | "source": [ 360 | "# append()\n", 361 | "# It adds new item on very last index\n", 362 | "# It add one item at a time" 363 | ] 364 | }, 365 | { 366 | "cell_type": "code", 367 | "execution_count": 38, 368 | "metadata": {}, 369 | "outputs": [ 370 | { 371 | "name": "stdout", 372 | "output_type": "stream", 373 | "text": [ 374 | "[]\n" 375 | ] 376 | } 377 | ], 378 | "source": [ 379 | "empty_list= []\n", 380 | "print(empty_list)" 381 | ] 382 | }, 383 | { 384 | "cell_type": "code", 385 | "execution_count": null, 386 | "metadata": {}, 387 | "outputs": [], 388 | "source": [ 389 | "empty_list.append(\"Computer\")\n", 390 | "print(empty_list)" 391 | ] 392 | }, 393 | { 394 | "cell_type": "code", 395 | "execution_count": 42, 396 | "metadata": {}, 397 | "outputs": [ 398 | { 399 | "name": "stdout", 400 | "output_type": "stream", 401 | "text": [ 402 | "['Computer', 'Computer', 'Computer', 'Laptop']\n" 403 | ] 404 | } 405 | ], 406 | "source": [ 407 | "empty_list.append(\"Laptop\")\n", 408 | "print(empty_list)" 409 | ] 410 | }, 411 | { 412 | "cell_type": "code", 413 | "execution_count": 43, 414 | "metadata": {}, 415 | "outputs": [], 416 | "source": [ 417 | "del(empty_list)" 418 | ] 419 | }, 420 | { 421 | "cell_type": "code", 422 | "execution_count": 44, 423 | "metadata": {}, 424 | "outputs": [ 425 | { 426 | "ename": "NameError", 427 | "evalue": "name 'empty_list' is not defined", 428 | "output_type": "error", 429 | "traceback": [ 430 | "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", 431 | "\u001b[1;31mNameError\u001b[0m Traceback (most recent call last)", 432 | "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mempty_list\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", 433 | "\u001b[1;31mNameError\u001b[0m: name 'empty_list' is not defined" 434 | ] 435 | } 436 | ], 437 | "source": [ 438 | "print(empty_list)" 439 | ] 440 | }, 441 | { 442 | "cell_type": "code", 443 | "execution_count": 45, 444 | "metadata": {}, 445 | "outputs": [ 446 | { 447 | "name": "stdout", 448 | "output_type": "stream", 449 | "text": [ 450 | "[]\n" 451 | ] 452 | } 453 | ], 454 | "source": [ 455 | "empty_list= []\n", 456 | "print(empty_list)" 457 | ] 458 | }, 459 | { 460 | "cell_type": "code", 461 | "execution_count": 46, 462 | "metadata": {}, 463 | "outputs": [ 464 | { 465 | "name": "stdout", 466 | "output_type": "stream", 467 | "text": [ 468 | "['Computer']\n" 469 | ] 470 | } 471 | ], 472 | "source": [ 473 | "empty_list.append(\"Computer\")\n", 474 | "print(empty_list)" 475 | ] 476 | }, 477 | { 478 | "cell_type": "code", 479 | "execution_count": 47, 480 | "metadata": {}, 481 | "outputs": [ 482 | { 483 | "name": "stdout", 484 | "output_type": "stream", 485 | "text": [ 486 | "['Computer', 'Laptop']\n" 487 | ] 488 | } 489 | ], 490 | "source": [ 491 | "empty_list.append(\"Laptop\")\n", 492 | "print(empty_list)" 493 | ] 494 | }, 495 | { 496 | "cell_type": "code", 497 | "execution_count": 48, 498 | "metadata": {}, 499 | "outputs": [ 500 | { 501 | "name": "stdout", 502 | "output_type": "stream", 503 | "text": [ 504 | "['Computer', 'Laptop', 'GPU']\n" 505 | ] 506 | } 507 | ], 508 | "source": [ 509 | "empty_list.append(\"GPU\")\n", 510 | "print(empty_list)" 511 | ] 512 | }, 513 | { 514 | "cell_type": "code", 515 | "execution_count": 49, 516 | "metadata": {}, 517 | "outputs": [], 518 | "source": [ 519 | "# Add elements to desired location\n", 520 | "# Takes index and value both for insert operation\n", 521 | "empty_list.insert(4,\"TPU\")\n" 522 | ] 523 | }, 524 | { 525 | "cell_type": "code", 526 | "execution_count": 50, 527 | "metadata": {}, 528 | "outputs": [ 529 | { 530 | "name": "stdout", 531 | "output_type": "stream", 532 | "text": [ 533 | "['Computer', 'Laptop', 'GPU', 'TPU']\n" 534 | ] 535 | } 536 | ], 537 | "source": [ 538 | "print(empty_list)" 539 | ] 540 | }, 541 | { 542 | "cell_type": "code", 543 | "execution_count": 52, 544 | "metadata": {}, 545 | "outputs": [ 546 | { 547 | "name": "stdout", 548 | "output_type": "stream", 549 | "text": [ 550 | "TPU\n" 551 | ] 552 | } 553 | ], 554 | "source": [ 555 | "print(empty_list[3])" 556 | ] 557 | }, 558 | { 559 | "cell_type": "code", 560 | "execution_count": 55, 561 | "metadata": {}, 562 | "outputs": [], 563 | "source": [ 564 | "staff = ['Asif','Saad','Hassan','Umer','Ahmed']\n", 565 | "faculty = ['Sahil', 'Waseem', 'Nasir Hussain']" 566 | ] 567 | }, 568 | { 569 | "cell_type": "code", 570 | "execution_count": 61, 571 | "metadata": {}, 572 | "outputs": [], 573 | "source": [ 574 | "employees = []" 575 | ] 576 | }, 577 | { 578 | "cell_type": "code", 579 | "execution_count": 57, 580 | "metadata": {}, 581 | "outputs": [], 582 | "source": [ 583 | "employees.append(staff)" 584 | ] 585 | }, 586 | { 587 | "cell_type": "code", 588 | "execution_count": 58, 589 | "metadata": {}, 590 | "outputs": [ 591 | { 592 | "data": { 593 | "text/plain": [ 594 | "[['Asif', 'Saad', 'Hassan', 'Umer', 'Ahmed']]" 595 | ] 596 | }, 597 | "execution_count": 58, 598 | "metadata": {}, 599 | "output_type": "execute_result" 600 | } 601 | ], 602 | "source": [ 603 | "employees" 604 | ] 605 | }, 606 | { 607 | "cell_type": "code", 608 | "execution_count": 59, 609 | "metadata": {}, 610 | "outputs": [], 611 | "source": [ 612 | "employees.extend(faculty)" 613 | ] 614 | }, 615 | { 616 | "cell_type": "code", 617 | "execution_count": 60, 618 | "metadata": {}, 619 | "outputs": [ 620 | { 621 | "data": { 622 | "text/plain": [ 623 | "[['Asif', 'Saad', 'Hassan', 'Umer', 'Ahmed'],\n", 624 | " 'Sahil',\n", 625 | " 'Waseem',\n", 626 | " 'Nasir Hussain']" 627 | ] 628 | }, 629 | "execution_count": 60, 630 | "metadata": {}, 631 | "output_type": "execute_result" 632 | } 633 | ], 634 | "source": [ 635 | "employees" 636 | ] 637 | }, 638 | { 639 | "cell_type": "code", 640 | "execution_count": 62, 641 | "metadata": {}, 642 | "outputs": [ 643 | { 644 | "data": { 645 | "text/plain": [ 646 | "[]" 647 | ] 648 | }, 649 | "execution_count": 62, 650 | "metadata": {}, 651 | "output_type": "execute_result" 652 | } 653 | ], 654 | "source": [ 655 | "employees" 656 | ] 657 | }, 658 | { 659 | "cell_type": "code", 660 | "execution_count": 95, 661 | "metadata": {}, 662 | "outputs": [], 663 | "source": [ 664 | "# + Operator for Adding List\n", 665 | "employees = staff + faculty" 666 | ] 667 | }, 668 | { 669 | "cell_type": "code", 670 | "execution_count": 97, 671 | "metadata": {}, 672 | "outputs": [ 673 | { 674 | "data": { 675 | "text/plain": [ 676 | "['Asif', 'Saad', 'Hassan', 'Umer', 'Ahmed', 'Sahil', 'Waseem', 'Nasir Hussain']" 677 | ] 678 | }, 679 | "execution_count": 97, 680 | "metadata": {}, 681 | "output_type": "execute_result" 682 | } 683 | ], 684 | "source": [ 685 | "employees" 686 | ] 687 | }, 688 | { 689 | "cell_type": "code", 690 | "execution_count": 76, 691 | "metadata": {}, 692 | "outputs": [], 693 | "source": [ 694 | "# Deleting item from List\n", 695 | "# del\n", 696 | "# Pop ()\n", 697 | "# remove ()\n", 698 | "# Clear()" 699 | ] 700 | }, 701 | { 702 | "cell_type": "code", 703 | "execution_count": 67, 704 | "metadata": {}, 705 | "outputs": [ 706 | { 707 | "data": { 708 | "text/plain": [ 709 | "['Asif', 'Saad', 'Hassan', 'Umer', 'Sahil', 'Waseem', 'Nasir Hussain']" 710 | ] 711 | }, 712 | "execution_count": 67, 713 | "metadata": {}, 714 | "output_type": "execute_result" 715 | } 716 | ], 717 | "source": [ 718 | "# del delete a value by index\n", 719 | "# del delete a value in memory\n", 720 | "del employees [4]\n", 721 | "employees" 722 | ] 723 | }, 724 | { 725 | "cell_type": "code", 726 | "execution_count": 71, 727 | "metadata": {}, 728 | "outputs": [ 729 | { 730 | "data": { 731 | "text/plain": [ 732 | "['Saad', 'Hassan', 'Umer', 'Sahil', 'Waseem', 'Nasir Hussain']" 733 | ] 734 | }, 735 | "execution_count": 71, 736 | "metadata": {}, 737 | "output_type": "execute_result" 738 | } 739 | ], 740 | "source": [ 741 | "employees" 742 | ] 743 | }, 744 | { 745 | "cell_type": "code", 746 | "execution_count": null, 747 | "metadata": {}, 748 | "outputs": [], 749 | "source": [ 750 | "# Pop ()\n", 751 | "# delete member permanently\n", 752 | "# delete from last index\n", 753 | "# return a value also\n", 754 | "# also take index" 755 | ] 756 | }, 757 | { 758 | "cell_type": "code", 759 | "execution_count": 77, 760 | "metadata": {}, 761 | "outputs": [], 762 | "source": [ 763 | "poped_item = employees.pop()" 764 | ] 765 | }, 766 | { 767 | "cell_type": "code", 768 | "execution_count": 78, 769 | "metadata": {}, 770 | "outputs": [ 771 | { 772 | "data": { 773 | "text/plain": [ 774 | "['Asif', 'Saad', 'Hassan', 'Umer', 'Ahmed', 'Sahil', 'Waseem']" 775 | ] 776 | }, 777 | "execution_count": 78, 778 | "metadata": {}, 779 | "output_type": "execute_result" 780 | } 781 | ], 782 | "source": [ 783 | "employees" 784 | ] 785 | }, 786 | { 787 | "cell_type": "code", 788 | "execution_count": 79, 789 | "metadata": {}, 790 | "outputs": [ 791 | { 792 | "data": { 793 | "text/plain": [ 794 | "'Nasir Hussain'" 795 | ] 796 | }, 797 | "execution_count": 79, 798 | "metadata": {}, 799 | "output_type": "execute_result" 800 | } 801 | ], 802 | "source": [ 803 | "poped_item" 804 | ] 805 | }, 806 | { 807 | "cell_type": "code", 808 | "execution_count": 83, 809 | "metadata": {}, 810 | "outputs": [], 811 | "source": [ 812 | "poped_item = employees.pop(2)" 813 | ] 814 | }, 815 | { 816 | "cell_type": "code", 817 | "execution_count": 84, 818 | "metadata": {}, 819 | "outputs": [ 820 | { 821 | "data": { 822 | "text/plain": [ 823 | "['Asif', 'Saad', 'Umer', 'Ahmed', 'Sahil', 'Waseem']" 824 | ] 825 | }, 826 | "execution_count": 84, 827 | "metadata": {}, 828 | "output_type": "execute_result" 829 | } 830 | ], 831 | "source": [ 832 | "employees" 833 | ] 834 | }, 835 | { 836 | "cell_type": "code", 837 | "execution_count": 85, 838 | "metadata": {}, 839 | "outputs": [ 840 | { 841 | "data": { 842 | "text/plain": [ 843 | "'Hassan'" 844 | ] 845 | }, 846 | "execution_count": 85, 847 | "metadata": {}, 848 | "output_type": "execute_result" 849 | } 850 | ], 851 | "source": [ 852 | "poped_item" 853 | ] 854 | }, 855 | { 856 | "cell_type": "code", 857 | "execution_count": 93, 858 | "metadata": {}, 859 | "outputs": [ 860 | { 861 | "ename": "IndexError", 862 | "evalue": "pop from empty list", 863 | "output_type": "error", 864 | "traceback": [ 865 | "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", 866 | "\u001b[1;31mIndexError\u001b[0m Traceback (most recent call last)", 867 | "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mpoped_item\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0memployees\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mpop\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", 868 | "\u001b[1;31mIndexError\u001b[0m: pop from empty list" 869 | ] 870 | } 871 | ], 872 | "source": [ 873 | "poped_item = employees.pop()" 874 | ] 875 | }, 876 | { 877 | "cell_type": "code", 878 | "execution_count": 98, 879 | "metadata": {}, 880 | "outputs": [ 881 | { 882 | "data": { 883 | "text/plain": [ 884 | "['Asif', 'Saad', 'Hassan', 'Umer', 'Ahmed', 'Sahil', 'Waseem', 'Nasir Hussain']" 885 | ] 886 | }, 887 | "execution_count": 98, 888 | "metadata": {}, 889 | "output_type": "execute_result" 890 | } 891 | ], 892 | "source": [ 893 | "employees" 894 | ] 895 | }, 896 | { 897 | "cell_type": "code", 898 | "execution_count": null, 899 | "metadata": {}, 900 | "outputs": [], 901 | "source": [ 902 | "# remove()\n", 903 | "# delete by value\n", 904 | "# permenantly remove" 905 | ] 906 | }, 907 | { 908 | "cell_type": "code", 909 | "execution_count": 99, 910 | "metadata": {}, 911 | "outputs": [], 912 | "source": [ 913 | "employees.remove('Asif')" 914 | ] 915 | }, 916 | { 917 | "cell_type": "code", 918 | "execution_count": 100, 919 | "metadata": {}, 920 | "outputs": [ 921 | { 922 | "data": { 923 | "text/plain": [ 924 | "['Saad', 'Hassan', 'Umer', 'Ahmed', 'Sahil', 'Waseem', 'Nasir Hussain']" 925 | ] 926 | }, 927 | "execution_count": 100, 928 | "metadata": {}, 929 | "output_type": "execute_result" 930 | } 931 | ], 932 | "source": [ 933 | "employees" 934 | ] 935 | }, 936 | { 937 | "cell_type": "code", 938 | "execution_count": 101, 939 | "metadata": {}, 940 | "outputs": [ 941 | { 942 | "ename": "ValueError", 943 | "evalue": "list.remove(x): x not in list", 944 | "output_type": "error", 945 | "traceback": [ 946 | "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", 947 | "\u001b[1;31mValueError\u001b[0m Traceback (most recent call last)", 948 | "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0memployees\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mremove\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'asif'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", 949 | "\u001b[1;31mValueError\u001b[0m: list.remove(x): x not in list" 950 | ] 951 | } 952 | ], 953 | "source": [ 954 | "employees.remove('asif')" 955 | ] 956 | }, 957 | { 958 | "cell_type": "code", 959 | "execution_count": null, 960 | "metadata": {}, 961 | "outputs": [], 962 | "source": [ 963 | "employees.remove()" 964 | ] 965 | }, 966 | { 967 | "cell_type": "code", 968 | "execution_count": 102, 969 | "metadata": {}, 970 | "outputs": [], 971 | "source": [ 972 | "copy_employees = employees.copy()" 973 | ] 974 | }, 975 | { 976 | "cell_type": "code", 977 | "execution_count": 103, 978 | "metadata": {}, 979 | "outputs": [ 980 | { 981 | "data": { 982 | "text/plain": [ 983 | "['Saad', 'Hassan', 'Umer', 'Ahmed', 'Sahil', 'Waseem', 'Nasir Hussain']" 984 | ] 985 | }, 986 | "execution_count": 103, 987 | "metadata": {}, 988 | "output_type": "execute_result" 989 | } 990 | ], 991 | "source": [ 992 | "copy_employees" 993 | ] 994 | }, 995 | { 996 | "cell_type": "code", 997 | "execution_count": 106, 998 | "metadata": {}, 999 | "outputs": [], 1000 | "source": [ 1001 | "existing_emloyees = employees" 1002 | ] 1003 | }, 1004 | { 1005 | "cell_type": "code", 1006 | "execution_count": 107, 1007 | "metadata": {}, 1008 | "outputs": [ 1009 | { 1010 | "data": { 1011 | "text/plain": [ 1012 | "['Saad', 'Hassan', 'Umer', 'Ahmed', 'Sahil', 'Waseem', 'Nasir Hussain']" 1013 | ] 1014 | }, 1015 | "execution_count": 107, 1016 | "metadata": {}, 1017 | "output_type": "execute_result" 1018 | } 1019 | ], 1020 | "source": [ 1021 | "existing_emloyees" 1022 | ] 1023 | }, 1024 | { 1025 | "cell_type": "code", 1026 | "execution_count": 108, 1027 | "metadata": {}, 1028 | "outputs": [], 1029 | "source": [ 1030 | "employees.remove('Ahmed')" 1031 | ] 1032 | }, 1033 | { 1034 | "cell_type": "code", 1035 | "execution_count": 109, 1036 | "metadata": {}, 1037 | "outputs": [ 1038 | { 1039 | "data": { 1040 | "text/plain": [ 1041 | "['Saad', 'Hassan', 'Umer', 'Sahil', 'Waseem', 'Nasir Hussain']" 1042 | ] 1043 | }, 1044 | "execution_count": 109, 1045 | "metadata": {}, 1046 | "output_type": "execute_result" 1047 | } 1048 | ], 1049 | "source": [ 1050 | "employees" 1051 | ] 1052 | }, 1053 | { 1054 | "cell_type": "code", 1055 | "execution_count": 110, 1056 | "metadata": {}, 1057 | "outputs": [ 1058 | { 1059 | "data": { 1060 | "text/plain": [ 1061 | "['Saad', 'Hassan', 'Umer', 'Sahil', 'Waseem', 'Nasir Hussain']" 1062 | ] 1063 | }, 1064 | "execution_count": 110, 1065 | "metadata": {}, 1066 | "output_type": "execute_result" 1067 | } 1068 | ], 1069 | "source": [ 1070 | "existing_emloyees" 1071 | ] 1072 | }, 1073 | { 1074 | "cell_type": "code", 1075 | "execution_count": 111, 1076 | "metadata": {}, 1077 | "outputs": [ 1078 | { 1079 | "data": { 1080 | "text/plain": [ 1081 | "['Saad', 'Hassan', 'Umer', 'Ahmed', 'Sahil', 'Waseem', 'Nasir Hussain']" 1082 | ] 1083 | }, 1084 | "execution_count": 111, 1085 | "metadata": {}, 1086 | "output_type": "execute_result" 1087 | } 1088 | ], 1089 | "source": [ 1090 | "copy_employees" 1091 | ] 1092 | }, 1093 | { 1094 | "cell_type": "code", 1095 | "execution_count": 117, 1096 | "metadata": {}, 1097 | "outputs": [ 1098 | { 1099 | "name": "stdout", 1100 | "output_type": "stream", 1101 | "text": [ 1102 | "1\n", 1103 | "0\n" 1104 | ] 1105 | } 1106 | ], 1107 | "source": [ 1108 | "print(employees.count('Saad'))\n", 1109 | "print(employees.index('Saad'))" 1110 | ] 1111 | }, 1112 | { 1113 | "cell_type": "code", 1114 | "execution_count": 125, 1115 | "metadata": {}, 1116 | "outputs": [ 1117 | { 1118 | "data": { 1119 | "text/plain": [ 1120 | "['Waseem', 'Umer', 'Sahil', 'Saad', 'Nasir Hussain', 'Hassan']" 1121 | ] 1122 | }, 1123 | "execution_count": 125, 1124 | "metadata": {}, 1125 | "output_type": "execute_result" 1126 | } 1127 | ], 1128 | "source": [ 1129 | "employees.sort(reverse=True)\n", 1130 | "employees" 1131 | ] 1132 | }, 1133 | { 1134 | "cell_type": "code", 1135 | "execution_count": 124, 1136 | "metadata": {}, 1137 | "outputs": [ 1138 | { 1139 | "data": { 1140 | "text/plain": [ 1141 | "['Waseem', 'Umer', 'Sahil', 'Saad', 'Nasir Hussain', 'Hassan']" 1142 | ] 1143 | }, 1144 | "execution_count": 124, 1145 | "metadata": {}, 1146 | "output_type": "execute_result" 1147 | } 1148 | ], 1149 | "source": [ 1150 | "employees.reverse()\n", 1151 | "employees" 1152 | ] 1153 | }, 1154 | { 1155 | "cell_type": "code", 1156 | "execution_count": 126, 1157 | "metadata": {}, 1158 | "outputs": [ 1159 | { 1160 | "data": { 1161 | "text/plain": [ 1162 | "['Hassan', 'Nasir Hussain', 'Saad', 'Sahil', 'Umer', 'Waseem']" 1163 | ] 1164 | }, 1165 | "execution_count": 126, 1166 | "metadata": {}, 1167 | "output_type": "execute_result" 1168 | } 1169 | ], 1170 | "source": [ 1171 | "employees.sort()\n", 1172 | "employees" 1173 | ] 1174 | }, 1175 | { 1176 | "cell_type": "code", 1177 | "execution_count": 3, 1178 | "metadata": {}, 1179 | "outputs": [ 1180 | { 1181 | "data": { 1182 | "text/plain": [ 1183 | "[1, 12, 23, 25, 36, 58, 53, 59, 98]" 1184 | ] 1185 | }, 1186 | "execution_count": 3, 1187 | "metadata": {}, 1188 | "output_type": "execute_result" 1189 | } 1190 | ], 1191 | "source": [ 1192 | "# Slicing\n", 1193 | "# performed on List and String\n", 1194 | "# copies the subset of values in a collection\n", 1195 | "nums = [1,12,23,25,36,58,53,59,98]\n", 1196 | "nums" 1197 | ] 1198 | }, 1199 | { 1200 | "cell_type": "code", 1201 | "execution_count": 4, 1202 | "metadata": {}, 1203 | "outputs": [ 1204 | { 1205 | "data": { 1206 | "text/plain": [ 1207 | "[23, 25, 36]" 1208 | ] 1209 | }, 1210 | "execution_count": 4, 1211 | "metadata": {}, 1212 | "output_type": "execute_result" 1213 | } 1214 | ], 1215 | "source": [ 1216 | "# takes two parameters Start index & end index\n", 1217 | "nums[2:5]" 1218 | ] 1219 | }, 1220 | { 1221 | "cell_type": "code", 1222 | "execution_count": 5, 1223 | "metadata": {}, 1224 | "outputs": [ 1225 | { 1226 | "data": { 1227 | "text/plain": [ 1228 | "[1, 12, 23, 25, 36]" 1229 | ] 1230 | }, 1231 | "execution_count": 5, 1232 | "metadata": {}, 1233 | "output_type": "execute_result" 1234 | } 1235 | ], 1236 | "source": [ 1237 | "nums[:5]" 1238 | ] 1239 | }, 1240 | { 1241 | "cell_type": "code", 1242 | "execution_count": 6, 1243 | "metadata": {}, 1244 | "outputs": [ 1245 | { 1246 | "data": { 1247 | "text/plain": [ 1248 | "[1, 12, 23, 25, 36, 58, 53, 59, 98]" 1249 | ] 1250 | }, 1251 | "execution_count": 6, 1252 | "metadata": {}, 1253 | "output_type": "execute_result" 1254 | } 1255 | ], 1256 | "source": [ 1257 | "nums[:]" 1258 | ] 1259 | }, 1260 | { 1261 | "cell_type": "code", 1262 | "execution_count": 7, 1263 | "metadata": {}, 1264 | "outputs": [ 1265 | { 1266 | "data": { 1267 | "text/plain": [ 1268 | "[1, 12, 23]" 1269 | ] 1270 | }, 1271 | "execution_count": 7, 1272 | "metadata": {}, 1273 | "output_type": "execute_result" 1274 | } 1275 | ], 1276 | "source": [ 1277 | "nums[0:3]" 1278 | ] 1279 | }, 1280 | { 1281 | "cell_type": "code", 1282 | "execution_count": 8, 1283 | "metadata": {}, 1284 | "outputs": [ 1285 | { 1286 | "data": { 1287 | "text/plain": [ 1288 | "[1, 12, 23, 25]" 1289 | ] 1290 | }, 1291 | "execution_count": 8, 1292 | "metadata": {}, 1293 | "output_type": "execute_result" 1294 | } 1295 | ], 1296 | "source": [ 1297 | "nums[:-5]" 1298 | ] 1299 | }, 1300 | { 1301 | "cell_type": "code", 1302 | "execution_count": 11, 1303 | "metadata": {}, 1304 | "outputs": [ 1305 | { 1306 | "data": { 1307 | "text/plain": [ 1308 | "[25, 36, 58]" 1309 | ] 1310 | }, 1311 | "execution_count": 11, 1312 | "metadata": {}, 1313 | "output_type": "execute_result" 1314 | } 1315 | ], 1316 | "source": [ 1317 | "nums[-6:-3]" 1318 | ] 1319 | }, 1320 | { 1321 | "cell_type": "code", 1322 | "execution_count": 12, 1323 | "metadata": {}, 1324 | "outputs": [ 1325 | { 1326 | "data": { 1327 | "text/plain": [ 1328 | "[23]" 1329 | ] 1330 | }, 1331 | "execution_count": 12, 1332 | "metadata": {}, 1333 | "output_type": "execute_result" 1334 | } 1335 | ], 1336 | "source": [ 1337 | "nums[2:3]" 1338 | ] 1339 | }, 1340 | { 1341 | "cell_type": "code", 1342 | "execution_count": 13, 1343 | "metadata": {}, 1344 | "outputs": [ 1345 | { 1346 | "data": { 1347 | "text/plain": [ 1348 | "[]" 1349 | ] 1350 | }, 1351 | "execution_count": 13, 1352 | "metadata": {}, 1353 | "output_type": "execute_result" 1354 | } 1355 | ], 1356 | "source": [ 1357 | "nums[7:1]" 1358 | ] 1359 | }, 1360 | { 1361 | "cell_type": "code", 1362 | "execution_count": 16, 1363 | "metadata": {}, 1364 | "outputs": [ 1365 | { 1366 | "data": { 1367 | "text/plain": [ 1368 | "[12, 25, 58]" 1369 | ] 1370 | }, 1371 | "execution_count": 16, 1372 | "metadata": {}, 1373 | "output_type": "execute_result" 1374 | } 1375 | ], 1376 | "source": [ 1377 | "# start,end,step\n", 1378 | "nums [1:7:2]" 1379 | ] 1380 | }, 1381 | { 1382 | "cell_type": "code", 1383 | "execution_count": 17, 1384 | "metadata": {}, 1385 | "outputs": [ 1386 | { 1387 | "data": { 1388 | "text/plain": [ 1389 | "[1, 23, 36, 53, 98]" 1390 | ] 1391 | }, 1392 | "execution_count": 17, 1393 | "metadata": {}, 1394 | "output_type": "execute_result" 1395 | } 1396 | ], 1397 | "source": [ 1398 | "nums [::2]" 1399 | ] 1400 | }, 1401 | { 1402 | "cell_type": "code", 1403 | "execution_count": 18, 1404 | "metadata": {}, 1405 | "outputs": [ 1406 | { 1407 | "data": { 1408 | "text/plain": [ 1409 | "[98, 53, 36, 23, 1]" 1410 | ] 1411 | }, 1412 | "execution_count": 18, 1413 | "metadata": {}, 1414 | "output_type": "execute_result" 1415 | } 1416 | ], 1417 | "source": [ 1418 | "nums [::-2]" 1419 | ] 1420 | }, 1421 | { 1422 | "cell_type": "code", 1423 | "execution_count": 19, 1424 | "metadata": {}, 1425 | "outputs": [ 1426 | { 1427 | "data": { 1428 | "text/plain": [ 1429 | "[]" 1430 | ] 1431 | }, 1432 | "execution_count": 19, 1433 | "metadata": {}, 1434 | "output_type": "execute_result" 1435 | } 1436 | ], 1437 | "source": [ 1438 | "nums [1:7:-1]" 1439 | ] 1440 | }, 1441 | { 1442 | "cell_type": "code", 1443 | "execution_count": 20, 1444 | "metadata": {}, 1445 | "outputs": [ 1446 | { 1447 | "data": { 1448 | "text/plain": [ 1449 | "[23, 25]" 1450 | ] 1451 | }, 1452 | "execution_count": 20, 1453 | "metadata": {}, 1454 | "output_type": "execute_result" 1455 | } 1456 | ], 1457 | "source": [ 1458 | "nums[-7:4]" 1459 | ] 1460 | }, 1461 | { 1462 | "cell_type": "code", 1463 | "execution_count": 31, 1464 | "metadata": {}, 1465 | "outputs": [], 1466 | "source": [ 1467 | "text = \"a day without python is an empty day\"" 1468 | ] 1469 | }, 1470 | { 1471 | "cell_type": "code", 1472 | "execution_count": 32, 1473 | "metadata": {}, 1474 | "outputs": [ 1475 | { 1476 | "data": { 1477 | "text/plain": [ 1478 | "'yad ytpme na si nohtyp tuohtiw yad a'" 1479 | ] 1480 | }, 1481 | "execution_count": 32, 1482 | "metadata": {}, 1483 | "output_type": "execute_result" 1484 | } 1485 | ], 1486 | "source": [ 1487 | "text[::-1]" 1488 | ] 1489 | }, 1490 | { 1491 | "cell_type": "code", 1492 | "execution_count": 36, 1493 | "metadata": {}, 1494 | "outputs": [ 1495 | { 1496 | "data": { 1497 | "text/plain": [ 1498 | "'A day without python is an empty day'" 1499 | ] 1500 | }, 1501 | "execution_count": 36, 1502 | "metadata": {}, 1503 | "output_type": "execute_result" 1504 | } 1505 | ], 1506 | "source": [ 1507 | "text.capitalize()" 1508 | ] 1509 | }, 1510 | { 1511 | "cell_type": "code", 1512 | "execution_count": 39, 1513 | "metadata": {}, 1514 | "outputs": [ 1515 | { 1516 | "data": { 1517 | "text/plain": [ 1518 | "'a day without python is an empty day'" 1519 | ] 1520 | }, 1521 | "execution_count": 39, 1522 | "metadata": {}, 1523 | "output_type": "execute_result" 1524 | } 1525 | ], 1526 | "source": [ 1527 | "text.lower()" 1528 | ] 1529 | }, 1530 | { 1531 | "cell_type": "code", 1532 | "execution_count": 42, 1533 | "metadata": {}, 1534 | "outputs": [], 1535 | "source": [ 1536 | "splitted = text.split()" 1537 | ] 1538 | }, 1539 | { 1540 | "cell_type": "code", 1541 | "execution_count": 43, 1542 | "metadata": {}, 1543 | "outputs": [ 1544 | { 1545 | "data": { 1546 | "text/plain": [ 1547 | "['a', 'day', 'without', 'python', 'is', 'an', 'empty', 'day']" 1548 | ] 1549 | }, 1550 | "execution_count": 43, 1551 | "metadata": {}, 1552 | "output_type": "execute_result" 1553 | } 1554 | ], 1555 | "source": [ 1556 | "splitted" 1557 | ] 1558 | }, 1559 | { 1560 | "cell_type": "code", 1561 | "execution_count": 44, 1562 | "metadata": {}, 1563 | "outputs": [ 1564 | { 1565 | "data": { 1566 | "text/plain": [ 1567 | "['day', 'empty', 'an', 'is', 'python', 'without', 'day', 'a']" 1568 | ] 1569 | }, 1570 | "execution_count": 44, 1571 | "metadata": {}, 1572 | "output_type": "execute_result" 1573 | } 1574 | ], 1575 | "source": [ 1576 | "reversed = splitted[::-1]\n", 1577 | "reversed" 1578 | ] 1579 | }, 1580 | { 1581 | "cell_type": "code", 1582 | "execution_count": 45, 1583 | "metadata": {}, 1584 | "outputs": [ 1585 | { 1586 | "data": { 1587 | "text/plain": [ 1588 | "'day empty an is python without day a'" 1589 | ] 1590 | }, 1591 | "execution_count": 45, 1592 | "metadata": {}, 1593 | "output_type": "execute_result" 1594 | } 1595 | ], 1596 | "source": [ 1597 | "' '.join(reversed)" 1598 | ] 1599 | }, 1600 | { 1601 | "cell_type": "code", 1602 | "execution_count": 48, 1603 | "metadata": {}, 1604 | "outputs": [ 1605 | { 1606 | "data": { 1607 | "text/plain": [ 1608 | "'a****b'" 1609 | ] 1610 | }, 1611 | "execution_count": 48, 1612 | "metadata": {}, 1613 | "output_type": "execute_result" 1614 | } 1615 | ], 1616 | "source": [ 1617 | "\"****\".join(['a','b'])" 1618 | ] 1619 | }, 1620 | { 1621 | "cell_type": "code", 1622 | "execution_count": 49, 1623 | "metadata": {}, 1624 | "outputs": [ 1625 | { 1626 | "data": { 1627 | "text/plain": [ 1628 | "'a b'" 1629 | ] 1630 | }, 1631 | "execution_count": 49, 1632 | "metadata": {}, 1633 | "output_type": "execute_result" 1634 | } 1635 | ], 1636 | "source": [ 1637 | "\" \".join(['a','b'])" 1638 | ] 1639 | }, 1640 | { 1641 | "cell_type": "code", 1642 | "execution_count": 50, 1643 | "metadata": {}, 1644 | "outputs": [ 1645 | { 1646 | "data": { 1647 | "text/plain": [ 1648 | "'day empty an is python without day a'" 1649 | ] 1650 | }, 1651 | "execution_count": 50, 1652 | "metadata": {}, 1653 | "output_type": "execute_result" 1654 | } 1655 | ], 1656 | "source": [ 1657 | "\" \".join(text.split()[::-1])" 1658 | ] 1659 | }, 1660 | { 1661 | "cell_type": "code", 1662 | "execution_count": 53, 1663 | "metadata": {}, 1664 | "outputs": [ 1665 | { 1666 | "data": { 1667 | "text/plain": [ 1668 | "'a day without python is an empty day'" 1669 | ] 1670 | }, 1671 | "execution_count": 53, 1672 | "metadata": {}, 1673 | "output_type": "execute_result" 1674 | } 1675 | ], 1676 | "source": [ 1677 | "\" \".join(text.split()[::1])" 1678 | ] 1679 | }, 1680 | { 1681 | "cell_type": "code", 1682 | "execution_count": 5, 1683 | "metadata": {}, 1684 | "outputs": [], 1685 | "source": [ 1686 | "a = [1,2,3,4,5]" 1687 | ] 1688 | }, 1689 | { 1690 | "cell_type": "code", 1691 | "execution_count": 3, 1692 | "metadata": {}, 1693 | "outputs": [], 1694 | "source": [ 1695 | "a.remove(3)" 1696 | ] 1697 | }, 1698 | { 1699 | "cell_type": "code", 1700 | "execution_count": 4, 1701 | "metadata": {}, 1702 | "outputs": [ 1703 | { 1704 | "data": { 1705 | "text/plain": [ 1706 | "[1, 2, 4, 5]" 1707 | ] 1708 | }, 1709 | "execution_count": 4, 1710 | "metadata": {}, 1711 | "output_type": "execute_result" 1712 | } 1713 | ], 1714 | "source": [ 1715 | "a" 1716 | ] 1717 | }, 1718 | { 1719 | "cell_type": "code", 1720 | "execution_count": 6, 1721 | "metadata": {}, 1722 | "outputs": [ 1723 | { 1724 | "data": { 1725 | "text/plain": [ 1726 | "[1, 2, 3, 4, 5]" 1727 | ] 1728 | }, 1729 | "execution_count": 6, 1730 | "metadata": {}, 1731 | "output_type": "execute_result" 1732 | } 1733 | ], 1734 | "source": [ 1735 | "a" 1736 | ] 1737 | }, 1738 | { 1739 | "cell_type": "code", 1740 | "execution_count": 7, 1741 | "metadata": {}, 1742 | "outputs": [ 1743 | { 1744 | "data": { 1745 | "text/plain": [ 1746 | "[]" 1747 | ] 1748 | }, 1749 | "execution_count": 7, 1750 | "metadata": {}, 1751 | "output_type": "execute_result" 1752 | } 1753 | ], 1754 | "source": [ 1755 | "a[2:2]" 1756 | ] 1757 | }, 1758 | { 1759 | "cell_type": "code", 1760 | "execution_count": 8, 1761 | "metadata": {}, 1762 | "outputs": [], 1763 | "source": [ 1764 | "a[2:3] = []" 1765 | ] 1766 | }, 1767 | { 1768 | "cell_type": "code", 1769 | "execution_count": 9, 1770 | "metadata": {}, 1771 | "outputs": [ 1772 | { 1773 | "data": { 1774 | "text/plain": [ 1775 | "[1, 2, 4, 5]" 1776 | ] 1777 | }, 1778 | "execution_count": 9, 1779 | "metadata": {}, 1780 | "output_type": "execute_result" 1781 | } 1782 | ], 1783 | "source": [ 1784 | "a" 1785 | ] 1786 | }, 1787 | { 1788 | "cell_type": "code", 1789 | "execution_count": 27, 1790 | "metadata": {}, 1791 | "outputs": [], 1792 | "source": [ 1793 | "b=['a','b','c']" 1794 | ] 1795 | }, 1796 | { 1797 | "cell_type": "code", 1798 | "execution_count": 18, 1799 | "metadata": {}, 1800 | "outputs": [], 1801 | "source": [ 1802 | "b[len(b):]=['d','e']" 1803 | ] 1804 | }, 1805 | { 1806 | "cell_type": "code", 1807 | "execution_count": 23, 1808 | "metadata": {}, 1809 | "outputs": [ 1810 | { 1811 | "data": { 1812 | "text/plain": [ 1813 | "['a', 'b', 'c']" 1814 | ] 1815 | }, 1816 | "execution_count": 23, 1817 | "metadata": {}, 1818 | "output_type": "execute_result" 1819 | } 1820 | ], 1821 | "source": [ 1822 | "b" 1823 | ] 1824 | }, 1825 | { 1826 | "cell_type": "code", 1827 | "execution_count": 24, 1828 | "metadata": {}, 1829 | "outputs": [], 1830 | "source": [ 1831 | "b+='de'" 1832 | ] 1833 | }, 1834 | { 1835 | "cell_type": "code", 1836 | "execution_count": 26, 1837 | "metadata": {}, 1838 | "outputs": [ 1839 | { 1840 | "data": { 1841 | "text/plain": [ 1842 | "['a', 'b', 'c', 'd', 'e']" 1843 | ] 1844 | }, 1845 | "execution_count": 26, 1846 | "metadata": {}, 1847 | "output_type": "execute_result" 1848 | } 1849 | ], 1850 | "source": [ 1851 | "b" 1852 | ] 1853 | }, 1854 | { 1855 | "cell_type": "code", 1856 | "execution_count": 28, 1857 | "metadata": {}, 1858 | "outputs": [ 1859 | { 1860 | "data": { 1861 | "text/plain": [ 1862 | "['a', 'b', 'c']" 1863 | ] 1864 | }, 1865 | "execution_count": 28, 1866 | "metadata": {}, 1867 | "output_type": "execute_result" 1868 | } 1869 | ], 1870 | "source": [ 1871 | "b" 1872 | ] 1873 | }, 1874 | { 1875 | "cell_type": "code", 1876 | "execution_count": 29, 1877 | "metadata": {}, 1878 | "outputs": [], 1879 | "source": [ 1880 | "b[-1:] = ['d','e']" 1881 | ] 1882 | }, 1883 | { 1884 | "cell_type": "code", 1885 | "execution_count": 30, 1886 | "metadata": {}, 1887 | "outputs": [ 1888 | { 1889 | "data": { 1890 | "text/plain": [ 1891 | "['a', 'b', 'd', 'e']" 1892 | ] 1893 | }, 1894 | "execution_count": 30, 1895 | "metadata": {}, 1896 | "output_type": "execute_result" 1897 | } 1898 | ], 1899 | "source": [ 1900 | "b" 1901 | ] 1902 | }, 1903 | { 1904 | "cell_type": "code", 1905 | "execution_count": 33, 1906 | "metadata": {}, 1907 | "outputs": [], 1908 | "source": [ 1909 | "t=(\"foo\",)" 1910 | ] 1911 | }, 1912 | { 1913 | "cell_type": "code", 1914 | "execution_count": 34, 1915 | "metadata": {}, 1916 | "outputs": [ 1917 | { 1918 | "data": { 1919 | "text/plain": [ 1920 | "tuple" 1921 | ] 1922 | }, 1923 | "execution_count": 34, 1924 | "metadata": {}, 1925 | "output_type": "execute_result" 1926 | } 1927 | ], 1928 | "source": [ 1929 | "type(t)" 1930 | ] 1931 | }, 1932 | { 1933 | "cell_type": "code", 1934 | "execution_count": null, 1935 | "metadata": {}, 1936 | "outputs": [], 1937 | "source": [] 1938 | } 1939 | ], 1940 | "metadata": { 1941 | "kernelspec": { 1942 | "display_name": "Python 3", 1943 | "language": "python", 1944 | "name": "python3" 1945 | }, 1946 | "language_info": { 1947 | "codemirror_mode": { 1948 | "name": "ipython", 1949 | "version": 3 1950 | }, 1951 | "file_extension": ".py", 1952 | "mimetype": "text/x-python", 1953 | "name": "python", 1954 | "nbconvert_exporter": "python", 1955 | "pygments_lexer": "ipython3", 1956 | "version": "3.7.4" 1957 | } 1958 | }, 1959 | "nbformat": 4, 1960 | "nbformat_minor": 2 1961 | } 1962 | --------------------------------------------------------------------------------