Format: application/octet-stream
⬇ Download File (14.3 KB)
   1  {
   2   "cells": [
   3    {
   4     "cell_type": "code",
   5     "execution_count": 12,
   6     "id": "1d8bfef7",
   7     "metadata": {},
   8     "outputs": [],
   9     "source": [
  10      "l= [x for x in range(1,10001) if x%7==0 and x%13==0 and x%17==0]\n",
  11      "d= dict(zip(range(1,len(l)+1),  l))"
  12     ]
  13    },
  14    {
  15     "cell_type": "code",
  16     "execution_count": 13,
  17     "id": "447cd9dd",
  18     "metadata": {},
  19     "outputs": [
  20      {
  21       "data": {
  22        "text/plain": [
  23         "{1: 1547, 2: 3094, 3: 4641, 4: 6188, 5: 7735, 6: 9282}"
  24        ]
  25       },
  26       "execution_count": 13,
  27       "metadata": {},
  28       "output_type": "execute_result"
  29      }
  30     ],
  31     "source": [
  32      "d"
  33     ]
  34    },
  35    {
  36     "cell_type": "code",
  37     "execution_count": 14,
  38     "id": "17f3bc39",
  39     "metadata": {},
  40     "outputs": [
  41      {
  42       "data": {
  43        "text/plain": [
  44         "1547"
  45        ]
  46       },
  47       "execution_count": 14,
  48       "metadata": {},
  49       "output_type": "execute_result"
  50      }
  51     ],
  52     "source": [
  53      "d[1]"
  54     ]
  55    },
  56    {
  57     "cell_type": "code",
  58     "execution_count": 18,
  59     "id": "ea65e073",
  60     "metadata": {},
  61     "outputs": [
  62      {
  63       "data": {
  64        "text/plain": [
  65         "1547"
  66        ]
  67       },
  68       "execution_count": 18,
  69       "metadata": {},
  70       "output_type": "execute_result"
  71      }
  72     ],
  73     "source": [
  74      "d.pop(1)"
  75     ]
  76    },
  77    {
  78     "cell_type": "code",
  79     "execution_count": 25,
  80     "id": "9c0427fe",
  81     "metadata": {},
  82     "outputs": [
  83      {
  84       "data": {
  85        "text/plain": [
  86         "(6, 9282)"
  87        ]
  88       },
  89       "execution_count": 25,
  90       "metadata": {},
  91       "output_type": "execute_result"
  92      }
  93     ],
  94     "source": [
  95      "d.popitem()"
  96     ]
  97    },
  98    {
  99     "cell_type": "code",
 100     "execution_count": 30,
 101     "id": "8b46ce21",
 102     "metadata": {},
 103     "outputs": [
 104      {
 105       "data": {
 106        "text/plain": [
 107         "dict_values([3094, 4641, 6188, 7735])"
 108        ]
 109       },
 110       "execution_count": 30,
 111       "metadata": {},
 112       "output_type": "execute_result"
 113      }
 114     ],
 115     "source": [
 116      "d.values()"
 117     ]
 118    },
 119    {
 120     "cell_type": "code",
 121     "execution_count": 31,
 122     "id": "a716746f",
 123     "metadata": {},
 124     "outputs": [],
 125     "source": [
 126      "s= 'hi hhow are you'"
 127     ]
 128    },
 129    {
 130     "cell_type": "code",
 131     "execution_count": 32,
 132     "id": "39159c10",
 133     "metadata": {},
 134     "outputs": [
 135      {
 136       "data": {
 137        "text/plain": [
 138         "'Hi Hhow Are You'"
 139        ]
 140       },
 141       "execution_count": 32,
 142       "metadata": {},
 143       "output_type": "execute_result"
 144      }
 145     ],
 146     "source": [
 147      "s.title()"
 148     ]
 149    },
 150    {
 151     "cell_type": "code",
 152     "execution_count": 33,
 153     "id": "a005e224",
 154     "metadata": {},
 155     "outputs": [
 156      {
 157       "data": {
 158        "text/plain": [
 159         "4"
 160        ]
 161       },
 162       "execution_count": 33,
 163       "metadata": {},
 164       "output_type": "execute_result"
 165      }
 166     ],
 167     "source": [
 168      "len(s.split(' '))"
 169     ]
 170    },
 171    {
 172     "cell_type": "code",
 173     "execution_count": 34,
 174     "id": "8f241de3",
 175     "metadata": {},
 176     "outputs": [
 177      {
 178       "data": {
 179        "text/plain": [
 180         "15"
 181        ]
 182       },
 183       "execution_count": 34,
 184       "metadata": {},
 185       "output_type": "execute_result"
 186      }
 187     ],
 188     "source": [
 189      "len(s)"
 190     ]
 191    },
 192    {
 193     "cell_type": "code",
 194     "execution_count": 36,
 195     "id": "c9cc50b4",
 196     "metadata": {},
 197     "outputs": [],
 198     "source": [
 199      "l=list(s)"
 200     ]
 201    },
 202    {
 203     "cell_type": "code",
 204     "execution_count": 37,
 205     "id": "ea6eb40c",
 206     "metadata": {},
 207     "outputs": [
 208      {
 209       "data": {
 210        "text/plain": [
 211         "['h', 'i', ' ', 'h', 'h', 'o', 'w', ' ', 'a', 'r', 'e', ' ', 'y', 'o', 'u']"
 212        ]
 213       },
 214       "execution_count": 37,
 215       "metadata": {},
 216       "output_type": "execute_result"
 217      }
 218     ],
 219     "source": [
 220      "l"
 221     ]
 222    },
 223    {
 224     "cell_type": "code",
 225     "execution_count": 61,
 226     "id": "b9bfd234",
 227     "metadata": {},
 228     "outputs": [],
 229     "source": [
 230      "d = {\n",
 231      "  \"name\": \"Dog\",\n",
 232      "  \"age\":5,\n",
 233      "  \"Weight\": 4,\n",
 234      "  \"Country\": \"US\",\n",
 235      "  \"City\":\"California\"\n",
 236      "   \n",
 237      "}\n"
 238     ]
 239    },
 240    {
 241     "cell_type": "code",
 242     "execution_count": 40,
 243     "id": "a361e0a4",
 244     "metadata": {},
 245     "outputs": [
 246      {
 247       "data": {
 248        "text/plain": [
 249         "{'name': 'Dog', 'age': 5}"
 250        ]
 251       },
 252       "execution_count": 40,
 253       "metadata": {},
 254       "output_type": "execute_result"
 255      }
 256     ],
 257     "source": [
 258      "dict(zip(['name', 'age'], [d['name'], d['age']]))"
 259     ]
 260    },
 261    {
 262     "cell_type": "code",
 263     "execution_count": 45,
 264     "id": "c0bb82c4",
 265     "metadata": {},
 266     "outputs": [],
 267     "source": [
 268      "del d['name'], d['age']"
 269     ]
 270    },
 271    {
 272     "cell_type": "code",
 273     "execution_count": null,
 274     "id": "5bb63b58",
 275     "metadata": {},
 276     "outputs": [],
 277     "source": []
 278    },
 279    {
 280     "cell_type": "code",
 281     "execution_count": 69,
 282     "id": "e9225663",
 283     "metadata": {},
 284     "outputs": [],
 285     "source": [
 286      "d= {'b':5,'a':1,'D':4}"
 287     ]
 288    },
 289    {
 290     "cell_type": "code",
 291     "execution_count": 59,
 292     "id": "90e6175a",
 293     "metadata": {},
 294     "outputs": [
 295      {
 296       "name": "stdout",
 297       "output_type": "stream",
 298       "text": [
 299        "4\n",
 300        "1\n",
 301        "5\n"
 302       ]
 303      }
 304     ],
 305     "source": [
 306      "for _ in sorted(d):\n",
 307      "    print(d[_])"
 308     ]
 309    },
 310    {
 311     "cell_type": "code",
 312     "execution_count": 60,
 313     "id": "2b6811aa",
 314     "metadata": {},
 315     "outputs": [
 316      {
 317       "data": {
 318        "text/plain": [
 319         "2550608643392"
 320        ]
 321       },
 322       "execution_count": 60,
 323       "metadata": {},
 324       "output_type": "execute_result"
 325      }
 326     ],
 327     "source": [
 328      "id(d)"
 329     ]
 330    },
 331    {
 332     "cell_type": "code",
 333     "execution_count": 62,
 334     "id": "e5c5970c",
 335     "metadata": {},
 336     "outputs": [],
 337     "source": [
 338      "d['animalname']= d.pop('name')"
 339     ]
 340    },
 341    {
 342     "cell_type": "code",
 343     "execution_count": 63,
 344     "id": "45282325",
 345     "metadata": {},
 346     "outputs": [
 347      {
 348       "data": {
 349        "text/plain": [
 350         "{'age': 5,\n",
 351         " 'Weight': 4,\n",
 352         " 'Country': 'US',\n",
 353         " 'City': 'California',\n",
 354         " 'animalname': 'Dog'}"
 355        ]
 356       },
 357       "execution_count": 63,
 358       "metadata": {},
 359       "output_type": "execute_result"
 360      }
 361     ],
 362     "source": [
 363      "d"
 364     ]
 365    },
 366    {
 367     "cell_type": "code",
 368     "execution_count": 65,
 369     "id": "71e96cdb",
 370     "metadata": {},
 371     "outputs": [
 372      {
 373       "ename": "TypeError",
 374       "evalue": "unhashable type: 'list'",
 375       "output_type": "error",
 376       "traceback": [
 377        "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
 378        "\u001b[1;31mTypeError\u001b[0m                                 Traceback (most recent call last)",
 379        "\u001b[1;32m<ipython-input-65-fa3104c36ec4>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0md\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'age'\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;34m'animalname'\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",
 380        "\u001b[1;31mTypeError\u001b[0m: unhashable type: 'list'"
 381       ]
 382      }
 383     ],
 384     "source": [
 385      "d[['age','animalname']]"
 386     ]
 387    },
 388    {
 389     "cell_type": "code",
 390     "execution_count": 67,
 391     "id": "4ef785be",
 392     "metadata": {},
 393     "outputs": [],
 394     "source": [
 395      "if 'age' in d:\n",
 396      "    del d['age']"
 397     ]
 398    },
 399    {
 400     "cell_type": "code",
 401     "execution_count": 68,
 402     "id": "31af363e",
 403     "metadata": {},
 404     "outputs": [
 405      {
 406       "data": {
 407        "text/plain": [
 408         "{'Weight': 4, 'Country': 'US', 'City': 'California', 'animalname': 'Dog'}"
 409        ]
 410       },
 411       "execution_count": 68,
 412       "metadata": {},
 413       "output_type": "execute_result"
 414      }
 415     ],
 416     "source": [
 417      "d"
 418     ]
 419    },
 420    {
 421     "cell_type": "code",
 422     "execution_count": 74,
 423     "id": "d964f89e",
 424     "metadata": {},
 425     "outputs": [],
 426     "source": [
 427      "d.get?"
 428     ]
 429    },
 430    {
 431     "cell_type": "code",
 432     "execution_count": 76,
 433     "id": "936ed7d9",
 434     "metadata": {},
 435     "outputs": [
 436      {
 437       "data": {
 438        "text/plain": [
 439         "'a'"
 440        ]
 441       },
 442       "execution_count": 76,
 443       "metadata": {},
 444       "output_type": "execute_result"
 445      }
 446     ],
 447     "source": [
 448      "min(d, key= d.get)"
 449     ]
 450    },
 451    {
 452     "cell_type": "code",
 453     "execution_count": 77,
 454     "id": "01807f4e",
 455     "metadata": {},
 456     "outputs": [
 457      {
 458       "data": {
 459        "text/plain": [
 460         "{'b': 5, 'a': 1, 'D': 4}"
 461        ]
 462       },
 463       "execution_count": 77,
 464       "metadata": {},
 465       "output_type": "execute_result"
 466      }
 467     ],
 468     "source": [
 469      "d"
 470     ]
 471    },
 472    {
 473     "cell_type": "code",
 474     "execution_count": 80,
 475     "id": "ee25a88c",
 476     "metadata": {},
 477     "outputs": [
 478      {
 479       "data": {
 480        "text/plain": [
 481         "['b', 'D']"
 482        ]
 483       },
 484       "execution_count": 80,
 485       "metadata": {},
 486       "output_type": "execute_result"
 487      }
 488     ],
 489     "source": [
 490      "sorted(d, key= d.get,reverse=1)[:2]"
 491     ]
 492    },
 493    {
 494     "cell_type": "code",
 495     "execution_count": null,
 496     "id": "175ab083",
 497     "metadata": {},
 498     "outputs": [],
 499     "source": []
 500    },
 501    {
 502     "cell_type": "code",
 503     "execution_count": 94,
 504     "id": "8a96eb7e",
 505     "metadata": {},
 506     "outputs": [],
 507     "source": [
 508      "d= {'Fr   uit':['Apple','Banana','Orange'],'Sub   ject':['Phy','Math','English']}"
 509     ]
 510    },
 511    {
 512     "cell_type": "code",
 513     "execution_count": 96,
 514     "id": "d1429c18",
 515     "metadata": {},
 516     "outputs": [
 517      {
 518       "data": {
 519        "text/plain": [
 520         "{'Fruit': ['Apple', 'Banana', 'Orange'], 'Subject': ['Phy', 'Math', 'English']}"
 521        ]
 522       },
 523       "execution_count": 96,
 524       "metadata": {},
 525       "output_type": "execute_result"
 526      }
 527     ],
 528     "source": [
 529      "{x.replace(' ',''):d[x] for x in d.keys()}"
 530     ]
 531    },
 532    {
 533     "cell_type": "code",
 534     "execution_count": 97,
 535     "id": "06bc699e",
 536     "metadata": {},
 537     "outputs": [],
 538     "source": [
 539      "d = {'lang': 'C#', 'Fruit': 'Apple', 'Subj':None,'Animal':None}\n"
 540     ]
 541    },
 542    {
 543     "cell_type": "code",
 544     "execution_count": 100,
 545     "id": "b1644bb8",
 546     "metadata": {},
 547     "outputs": [
 548      {
 549       "data": {
 550        "text/plain": [
 551         "{'lang': 'C#', 'Fruit': 'Apple'}"
 552        ]
 553       },
 554       "execution_count": 100,
 555       "metadata": {},
 556       "output_type": "execute_result"
 557      }
 558     ],
 559     "source": [
 560      "{i: j for i,j in d.items() if j != None}"
 561     ]
 562    },
 563    {
 564     "cell_type": "code",
 565     "execution_count": 101,
 566     "id": "bcad3afe",
 567     "metadata": {},
 568     "outputs": [],
 569     "source": [
 570      "d={'Racx': 12000, 'Max':80000,'Stack':80000,'John':80000,}\n"
 571     ]
 572    },
 573    {
 574     "cell_type": "code",
 575     "execution_count": 104,
 576     "id": "b8c8087f",
 577     "metadata": {},
 578     "outputs": [
 579      {
 580       "data": {
 581        "text/plain": [
 582         "{12000: 1, 80000: 3}"
 583        ]
 584       },
 585       "execution_count": 104,
 586       "metadata": {},
 587       "output_type": "execute_result"
 588      }
 589     ],
 590     "source": [
 591      "{x : list(d.values()).count(x) for x in set(d.values())}"
 592     ]
 593    },
 594    {
 595     "cell_type": "code",
 596     "execution_count": null,
 597     "id": "6fc08bcc",
 598     "metadata": {},
 599     "outputs": [],
 600     "source": []
 601    },
 602    {
 603     "cell_type": "code",
 604     "execution_count": null,
 605     "id": "0b7dee95",
 606     "metadata": {},
 607     "outputs": [],
 608     "source": []
 609    },
 610    {
 611     "cell_type": "code",
 612     "execution_count": 105,
 613     "id": "0030c540",
 614     "metadata": {},
 615     "outputs": [],
 616     "source": [
 617      "s= 'hi how are you'"
 618     ]
 619    },
 620    {
 621     "cell_type": "code",
 622     "execution_count": 109,
 623     "id": "a7e63c02",
 624     "metadata": {},
 625     "outputs": [
 626      {
 627       "data": {
 628        "text/plain": [
 629         "'you are how hi'"
 630        ]
 631       },
 632       "execution_count": 109,
 633       "metadata": {},
 634       "output_type": "execute_result"
 635      }
 636     ],
 637     "source": [
 638      "' '.join(reversed(s.split(' ')))"
 639     ]
 640    },
 641    {
 642     "cell_type": "code",
 643     "execution_count": 115,
 644     "id": "50f79b95",
 645     "metadata": {},
 646     "outputs": [
 647      {
 648       "data": {
 649        "text/plain": [
 650         "['h', ' ', 'o', ' ', 'r', ' ', 'o']"
 651        ]
 652       },
 653       "execution_count": 115,
 654       "metadata": {},
 655       "output_type": "execute_result"
 656      }
 657     ],
 658     "source": [
 659      "[s[i] for i in range(len(s)) if i%2==0]"
 660     ]
 661    },
 662    {
 663     "cell_type": "code",
 664     "execution_count": 116,
 665     "id": "124f9024",
 666     "metadata": {},
 667     "outputs": [
 668      {
 669       "data": {
 670        "text/plain": [
 671         "True"
 672        ]
 673       },
 674       "execution_count": 116,
 675       "metadata": {},
 676       "output_type": "execute_result"
 677      }
 678     ],
 679     "source": [
 680      "s.startswith('hi')"
 681     ]
 682    },
 683    {
 684     "cell_type": "code",
 685     "execution_count": 117,
 686     "id": "0b175b7d",
 687     "metadata": {},
 688     "outputs": [
 689      {
 690       "data": {
 691        "text/plain": [
 692         "False"
 693        ]
 694       },
 695       "execution_count": 117,
 696       "metadata": {},
 697       "output_type": "execute_result"
 698      }
 699     ],
 700     "source": [
 701      "s.endswith('bye')"
 702     ]
 703    },
 704    {
 705     "cell_type": "code",
 706     "execution_count": 124,
 707     "id": "d1cc2d5b",
 708     "metadata": {},
 709     "outputs": [],
 710     "source": [
 711      "s= '\\nPython String\\n with\\n newline\\n'\n"
 712     ]
 713    },
 714    {
 715     "cell_type": "code",
 716     "execution_count": 126,
 717     "id": "03a5ee12",
 718     "metadata": {},
 719     "outputs": [
 720      {
 721       "name": "stdout",
 722       "output_type": "stream",
 723       "text": [
 724        "\n",
 725        "Python String\n",
 726        " with\n",
 727        " newline\n",
 728        "\n"
 729       ]
 730      }
 731     ],
 732     "source": [
 733      "print(s)"
 734     ]
 735    },
 736    {
 737     "cell_type": "code",
 738     "execution_count": 137,
 739     "id": "2fd9a97b",
 740     "metadata": {},
 741     "outputs": [],
 742     "source": [
 743      "s1 = \"Python is Amazing\"\n",
 744      "s2 = \"PythonProgram\""
 745     ]
 746    },
 747    {
 748     "cell_type": "code",
 749     "execution_count": 134,
 750     "id": "5f9d59e3",
 751     "metadata": {},
 752     "outputs": [
 753      {
 754       "data": {
 755        "text/plain": [
 756         "9"
 757        ]
 758       },
 759       "execution_count": 134,
 760       "metadata": {},
 761       "output_type": "execute_result"
 762      }
 763     ],
 764     "source": [
 765      "len([x for x in set(s1) if x in set(s2)])"
 766     ]
 767    },
 768    {
 769     "cell_type": "code",
 770     "execution_count": 138,
 771     "id": "2dcd5631",
 772     "metadata": {},
 773     "outputs": [
 774      {
 775       "data": {
 776        "text/plain": [
 777         "['Python', 'is', 'Amazing']"
 778        ]
 779       },
 780       "execution_count": 138,
 781       "metadata": {},
 782       "output_type": "execute_result"
 783      }
 784     ],
 785     "source": [
 786      "s1.split(' ')"
 787     ]
 788    },
 789    {
 790     "cell_type": "code",
 791     "execution_count": null,
 792     "id": "51b0f8b9",
 793     "metadata": {},
 794     "outputs": [],
 795     "source": [
 796      "{'Lower': }"
 797     ]
 798    }
 799   ],
 800   "metadata": {
 801    "kernelspec": {
 802     "display_name": "Python 3",
 803     "language": "python",
 804     "name": "python3"
 805    },
 806    "language_info": {
 807     "codemirror_mode": {
 808      "name": "ipython",
 809      "version": 3
 810     },
 811     "file_extension": ".py",
 812     "mimetype": "text/x-python",
 813     "name": "python",
 814     "nbconvert_exporter": "python",
 815     "pygments_lexer": "ipython3",
 816     "version": "3.8.8"
 817    }
 818   },
 819   "nbformat": 4,
 820   "nbformat_minor": 5
 821  }
 822