CoolFace
Datasetpublic

Ace-xvi/Generative_AI

sourceHugging Facemitupdated 11mo agoView on Hugging Face
0likes20downloads
Day 5-25-06-2023.ipynb2141 linesDownload Raw Back to 1_Adrash Python Session
1{2 "cells": [3  {4   "cell_type": "markdown",5   "id": "445446b0",6   "metadata": {},7   "source": [8    "# Day 5 .... 25-06-2023"9   ]10  },11  {12   "cell_type": "markdown",13   "id": "088ac9be",14   "metadata": {},15   "source": [16    "## Agenda\n",17    "   - Recap \n",18    "   - Dictionary Functions\n",19    "   - Activities on dictionaries\n",20    "   - Tuple\n",21    "   - Tuple functions\n",22    "   - Set\n",23    "   - Set functions\n",24    "   \n",25    "   - if else\n",26    "   - Single line if else / ternary operator"27   ]28  },29  {30   "cell_type": "code",31   "execution_count": 1,32   "id": "897b4625",33   "metadata": {},34   "outputs": [],35   "source": [36    "states_and_capitals = {'Karnataka':'Banglore','Kerala':'Trivindrum','Tamilnadu':'Chennai'}"37   ]38  },39  {40   "cell_type": "code",41   "execution_count": 2,42   "id": "1c5f4f93",43   "metadata": {},44   "outputs": [45    {46     "data": {47      "text/plain": [48       "'Banglore'"49      ]50     },51     "execution_count": 2,52     "metadata": {},53     "output_type": "execute_result"54    }55   ],56   "source": [57    "states_and_capitals['Karnataka']"58   ]59  },60  {61   "cell_type": "markdown",62   "id": "d5bfc8f9",63   "metadata": {},64   "source": [65    "### Accessing the elements of  a dictionary"66   ]67  },68  {69   "cell_type": "code",70   "execution_count": 3,71   "id": "b962ca8c",72   "metadata": {},73   "outputs": [],74   "source": [75    "# states_and_capitals['Andhra Pradesh']\n",76    "states_and_capitals.get('Andhra Pradesh')"77   ]78  },79  {80   "cell_type": "code",81   "execution_count": 4,82   "id": "42be2a27",83   "metadata": {},84   "outputs": [85    {86     "data": {87      "text/plain": [88       "'Banglore'"89      ]90     },91     "execution_count": 4,92     "metadata": {},93     "output_type": "execute_result"94    }95   ],96   "source": [97    "states_and_capitals.get('Karnataka')"98   ]99  },100  {101   "cell_type": "code",102   "execution_count": 6,103   "id": "93e5d977",104   "metadata": {},105   "outputs": [],106   "source": [107    "states_and_capitals.get('Andhra Pradesh')"108   ]109  },110  {111   "cell_type": "markdown",112   "id": "65ab0651",113   "metadata": {},114   "source": [115    "### Updating the dictionary using update and [  ]"116   ]117  },118  {119   "cell_type": "code",120   "execution_count": 8,121   "id": "1152e40a",122   "metadata": {},123   "outputs": [],124   "source": [125    "states_and_capitals.update({'Andhra Pradesh':'Vijawada'})"126   ]127  },128  {129   "cell_type": "code",130   "execution_count": 9,131   "id": "833ac2cc",132   "metadata": {},133   "outputs": [134    {135     "name": "stdout",136     "output_type": "stream",137     "text": [138      "{'Karnataka': 'Banglore', 'Kerala': 'Trivindrum', 'Tamilnadu': 'Chennai', 'Andhra Pradesh': 'Vijawada'}\n"139     ]140    }141   ],142   "source": [143    "print(states_and_capitals)"144   ]145  },146  {147   "cell_type": "code",148   "execution_count": 16,149   "id": "01bdeaba",150   "metadata": {},151   "outputs": [],152   "source": [153    "states_and_capitals.update({'Telangana':'Hyderabad','Maharastra':'Mumbai'})"154   ]155  },156  {157   "cell_type": "code",158   "execution_count": 21,159   "id": "fe815173",160   "metadata": {},161   "outputs": [162    {163     "name": "stdout",164     "output_type": "stream",165     "text": [166      "{'Karnataka': 'Banglore', 'Kerala': 'Trivindrum', 'Tamilnadu': 'Chennai', 'Andhra Pradesh': 'Vijawada', 'Telangana': 'Hyderabad', 'Maharastra': 'Mumbai'}\n"167     ]168    }169   ],170   "source": [171    "print(states_and_capitals)"172   ]173  },174  {175   "cell_type": "code",176   "execution_count": 22,177   "id": "0d16dd02",178   "metadata": {},179   "outputs": [],180   "source": [181    "states_and_capitals['Madhya Pradesh'] = 'Bhopal'"182   ]183  },184  {185   "cell_type": "code",186   "execution_count": 24,187   "id": "6a75c684",188   "metadata": {},189   "outputs": [190    {191     "name": "stdout",192     "output_type": "stream",193     "text": [194      "{'Karnataka': 'Banglore', 'Kerala': 'Trivindrum', 'Tamilnadu': 'Chennai', 'Andhra Pradesh': 'Vijawada', 'Telangana': 'Hyderabad', 'Maharastra': 'Mumbai', 'Madhya Pradesh': 'Bhopal'}\n"195     ]196    }197   ],198   "source": [199    "print(states_and_capitals)"200   ]201  },202  {203   "cell_type": "code",204   "execution_count": null,205   "id": "de052bc1",206   "metadata": {},207   "outputs": [],208   "source": [209    "### Similarly overwriting a value in list"210   ]211  },212  {213   "cell_type": "code",214   "execution_count": 26,215   "id": "dbea131e",216   "metadata": {},217   "outputs": [],218   "source": [219    "li = [1,2,3,4,5]"220   ]221  },222  {223   "cell_type": "code",224   "execution_count": 27,225   "id": "ae102274",226   "metadata": {},227   "outputs": [],228   "source": [229    "li[3]=873468764"230   ]231  },232  {233   "cell_type": "code",234   "execution_count": 28,235   "id": "59dbb3f9",236   "metadata": {},237   "outputs": [238    {239     "data": {240      "text/plain": [241       "[1, 2, 3, 873468764, 5]"242      ]243     },244     "execution_count": 28,245     "metadata": {},246     "output_type": "execute_result"247    }248   ],249   "source": [250    "li"251   ]252  },253  {254   "cell_type": "code",255   "execution_count": 42,256   "id": "c76c5cd9",257   "metadata": {},258   "outputs": [],259   "source": [260    "#### If there is already a key exist , it will overwrite with the new value"261   ]262  },263  {264   "cell_type": "code",265   "execution_count": 32,266   "id": "4a847fbb",267   "metadata": {},268   "outputs": [269    {270     "name": "stdout",271     "output_type": "stream",272     "text": [273      "{'Karnataka': 'Banglore', 'Kerala': 'Trivindrum', 'Tamilnadu': 'Chennai', 'Andhra Pradesh': 'Vijawada', 'Telangana': 'Hyderabad', 'Maharastra': 'Mumbai', 'Madhya Pradesh': 'Bhopal'}\n"274     ]275    }276   ],277   "source": [278    "print(states_and_capitals)"279   ]280  },281  {282   "cell_type": "code",283   "execution_count": 33,284   "id": "276b59c4",285   "metadata": {},286   "outputs": [],287   "source": [288    "states_and_capitals['Madhya Pradesh'] = '99999999999999999999'"289   ]290  },291  {292   "cell_type": "code",293   "execution_count": 35,294   "id": "a3bb64fd",295   "metadata": {},296   "outputs": [297    {298     "name": "stdout",299     "output_type": "stream",300     "text": [301      "{'Karnataka': 'Banglore', 'Kerala': 'Trivindrum', 'Tamilnadu': 'Chennai', 'Andhra Pradesh': 'Vijawada', 'Telangana': 'Hyderabad', 'Maharastra': 'Mumbai', 'Madhya Pradesh': '99999999999999999999'}\n"302     ]303    }304   ],305   "source": [306    "print(states_and_capitals)"307   ]308  },309  {310   "cell_type": "code",311   "execution_count": 36,312   "id": "b82dbee2",313   "metadata": {},314   "outputs": [],315   "source": [316    "states_and_capitals.update({'Andhra Pradesh': '555555555555'})"317   ]318  },319  {320   "cell_type": "code",321   "execution_count": 38,322   "id": "08467f03",323   "metadata": {},324   "outputs": [325    {326     "name": "stdout",327     "output_type": "stream",328     "text": [329      "{'Karnataka': 'Banglore', 'Kerala': 'Trivindrum', 'Tamilnadu': 'Chennai', 'Andhra Pradesh': '555555555555', 'Telangana': 'Hyderabad', 'Maharastra': 'Mumbai', 'Madhya Pradesh': '99999999999999999999'}\n"330     ]331    }332   ],333   "source": [334    "print(states_and_capitals)"335   ]336  },337  {338   "cell_type": "markdown",339   "id": "64a85e40",340   "metadata": {},341   "source": [342    "### Deleting a key "343   ]344  },345  {346   "cell_type": "code",347   "execution_count": 39,348   "id": "2d71fa5a",349   "metadata": {},350   "outputs": [],351   "source": [352    "del(states_and_capitals['Andhra Pradesh'])"353   ]354  },355  {356   "cell_type": "code",357   "execution_count": 43,358   "id": "0e181210",359   "metadata": {},360   "outputs": [361    {362     "name": "stdout",363     "output_type": "stream",364     "text": [365      "{'Karnataka': 'Banglore', 'Kerala': 'Trivindrum', 'Tamilnadu': 'Chennai', 'Telangana': 'Hyderabad', 'Maharastra': 'Mumbai', 'Madhya Pradesh': '99999999999999999999', 'Andhra Pradesh': 'Vijayawada'}\n"366     ]367    }368   ],369   "source": [370    "print(states_and_capitals)"371   ]372  },373  {374   "cell_type": "code",375   "execution_count": 41,376   "id": "d88d537f",377   "metadata": {},378   "outputs": [],379   "source": [380    "states_and_capitals['Andhra Pradesh']='Vijayawada'"381   ]382  },383  {384   "cell_type": "code",385   "execution_count": 44,386   "id": "936ca85d",387   "metadata": {},388   "outputs": [],389   "source": [390    "states_and_capitals['Madhya Pradesh']='Bhopal'"391   ]392  },393  {394   "cell_type": "code",395   "execution_count": 46,396   "id": "4fe9d26a",397   "metadata": {},398   "outputs": [399    {400     "name": "stdout",401     "output_type": "stream",402     "text": [403      "{'Karnataka': 'Banglore', 'Kerala': 'Trivindrum', 'Tamilnadu': 'Chennai', 'Telangana': 'Hyderabad', 'Maharastra': 'Mumbai', 'Madhya Pradesh': 'Bhopal', 'Andhra Pradesh': 'Vijayawada'}\n"404     ]405    }406   ],407   "source": [408    "print(states_and_capitals)"409   ]410  },411  {412   "cell_type": "markdown",413   "id": "adb78f23",414   "metadata": {},415   "source": [416    "### Get all the keys, values and key value , pairs"417   ]418  },419  {420   "cell_type": "code",421   "execution_count": 49,422   "id": "33a423ab",423   "metadata": {},424   "outputs": [425    {426     "name": "stdout",427     "output_type": "stream",428     "text": [429      "dict_keys(['Karnataka', 'Kerala', 'Tamilnadu', 'Telangana', 'Maharastra', 'Madhya Pradesh', 'Andhra Pradesh'])\n"430     ]431    }432   ],433   "source": [434    "print(states_and_capitals.keys())"435   ]436  },437  {438   "cell_type": "code",439   "execution_count": 50,440   "id": "7eafcea2",441   "metadata": {},442   "outputs": [443    {444     "name": "stdout",445     "output_type": "stream",446     "text": [447      "dict_values(['Banglore', 'Trivindrum', 'Chennai', 'Hyderabad', 'Mumbai', 'Bhopal', 'Vijayawada'])\n"448     ]449    }450   ],451   "source": [452    "print(states_and_capitals.values())"453   ]454  },455  {456   "cell_type": "code",457   "execution_count": 51,458   "id": "f95cb86e",459   "metadata": {},460   "outputs": [461    {462     "name": "stdout",463     "output_type": "stream",464     "text": [465      "dict_items([('Karnataka', 'Banglore'), ('Kerala', 'Trivindrum'), ('Tamilnadu', 'Chennai'), ('Telangana', 'Hyderabad'), ('Maharastra', 'Mumbai'), ('Madhya Pradesh', 'Bhopal'), ('Andhra Pradesh', 'Vijayawada')])\n"466     ]467    }468   ],469   "source": [470    "print(states_and_capitals.items())"471   ]472  },473  {474   "cell_type": "markdown",475   "id": "c43bfeb3",476   "metadata": {},477   "source": [478    "### Understanding difference between get and setdefault"479   ]480  },481  {482   "cell_type": "code",483   "execution_count": 52,484   "id": "1f1bd50f",485   "metadata": {},486   "outputs": [487    {488     "name": "stdout",489     "output_type": "stream",490     "text": [491      "None\n"492     ]493    }494   ],495   "source": [496    "print(states_and_capitals.get('Jharkand'))"497   ]498  },499  {500   "cell_type": "code",501   "execution_count": 53,502   "id": "bd735f57",503   "metadata": {},504   "outputs": [505    {506     "name": "stdout",507     "output_type": "stream",508     "text": [509      "{'Karnataka': 'Banglore', 'Kerala': 'Trivindrum', 'Tamilnadu': 'Chennai', 'Telangana': 'Hyderabad', 'Maharastra': 'Mumbai', 'Madhya Pradesh': 'Bhopal', 'Andhra Pradesh': 'Vijayawada'}\n"510     ]511    }512   ],513   "source": [514    "print(states_and_capitals)"515   ]516  },517  {518   "cell_type": "code",519   "execution_count": 54,520   "id": "588a1913",521   "metadata": {},522   "outputs": [523    {524     "name": "stdout",525     "output_type": "stream",526     "text": [527      "Ranchi\n"528     ]529    }530   ],531   "source": [532    "print(states_and_capitals.get('Jharkand','Ranchi'))  #### Only printing default vale, dictionary is not updated"533   ]534  },535  {536   "cell_type": "code",537   "execution_count": 55,538   "id": "7b808d69",539   "metadata": {},540   "outputs": [541    {542     "name": "stdout",543     "output_type": "stream",544     "text": [545      "{'Karnataka': 'Banglore', 'Kerala': 'Trivindrum', 'Tamilnadu': 'Chennai', 'Telangana': 'Hyderabad', 'Maharastra': 'Mumbai', 'Madhya Pradesh': 'Bhopal', 'Andhra Pradesh': 'Vijayawada'}\n"546     ]547    }548   ],549   "source": [550    "print(states_and_capitals)"551   ]552  },553  {554   "cell_type": "code",555   "execution_count": 56,556   "id": "9fd9d911",557   "metadata": {},558   "outputs": [559    {560     "name": "stdout",561     "output_type": "stream",562     "text": [563      "Ranchi\n"564     ]565    }566   ],567   "source": [568    "print(states_and_capitals.setdefault('Jharkand','Ranchi'))  #### Printing default value and also will update the dictionary"569   ]570  },571  {572   "cell_type": "code",573   "execution_count": 57,574   "id": "78d85c09",575   "metadata": {},576   "outputs": [577    {578     "name": "stdout",579     "output_type": "stream",580     "text": [581      "{'Karnataka': 'Banglore', 'Kerala': 'Trivindrum', 'Tamilnadu': 'Chennai', 'Telangana': 'Hyderabad', 'Maharastra': 'Mumbai', 'Madhya Pradesh': 'Bhopal', 'Andhra Pradesh': 'Vijayawada', 'Jharkand': 'Ranchi'}\n"582     ]583    }584   ],585   "source": [586    "print(states_and_capitals)"587   ]588  },589  {590   "cell_type": "markdown",591   "id": "05675a1e",592   "metadata": {},593   "source": [594    "### Understanding difference between update and setdefault"595   ]596  },597  {598   "cell_type": "code",599   "execution_count": 65,600   "id": "6f6c5be0",601   "metadata": {},602   "outputs": [],603   "source": [604    "states_and_capitals= {'Karnataka': 'Banglore', 'Kerala': 'Trivindrum', 'Tamilnadu': 'Chennai', \\\n",605    "                      'Telangana': 'Hyderabad', 'Maharastra': 'Mumbai', 'Madhya Pradesh': 'Bhopal', \\\n",606    "                      'Andhra Pradesh': 'Vijayawada', 'Jharkand': 'Ranchi'}"607   ]608  },609  {610   "cell_type": "code",611   "execution_count": 66,612   "id": "337fb0bb",613   "metadata": {},614   "outputs": [615    {616     "name": "stdout",617     "output_type": "stream",618     "text": [619      "{'Karnataka': 'Banglore', 'Kerala': 'Trivindrum', 'Tamilnadu': 'Chennai', 'Telangana': 'Hyderabad', 'Maharastra': 'Mumbai', 'Madhya Pradesh': 'Bhopal', 'Andhra Pradesh': 'Vijayawada', 'Jharkand': 'Ranchi'}\n"620     ]621    }622   ],623   "source": [624    "print(states_and_capitals)"625   ]626  },627  {628   "cell_type": "code",629   "execution_count": 67,630   "id": "0abbf55d",631   "metadata": {},632   "outputs": [633    {634     "name": "stdout",635     "output_type": "stream",636     "text": [637      "Ranchi\n"638     ]639    }640   ],641   "source": [642    "print(states_and_capitals.setdefault('Jharkand','Kolkata'))\n",643    "# Will update the dictionary only if the key not present.\n",644    "# In other words it will not overwrite if key already exist\n",645    "# If key is presnt it will return its value"646   ]647  },648  {649   "cell_type": "code",650   "execution_count": 68,651   "id": "89ba3071",652   "metadata": {},653   "outputs": [654    {655     "name": "stdout",656     "output_type": "stream",657     "text": [658      "{'Karnataka': 'Banglore', 'Kerala': 'Trivindrum', 'Tamilnadu': 'Chennai', 'Telangana': 'Hyderabad', 'Maharastra': 'Mumbai', 'Madhya Pradesh': 'Bhopal', 'Andhra Pradesh': 'Vijayawada', 'Jharkand': 'Ranchi'}\n"659     ]660    }661   ],662   "source": [663    "print(states_and_capitals)"664   ]665  },666  {667   "cell_type": "code",668   "execution_count": 69,669   "id": "174a5b55",670   "metadata": {},671   "outputs": [672    {673     "name": "stdout",674     "output_type": "stream",675     "text": [676      "None\n"677     ]678    }679   ],680   "source": [681    "print(states_and_capitals.update({'Jharkand':'Kolkata'}))\n",682    "# It will update if key is not present\n",683    "# If key already exist, it will overwrite the existing value with new value \n",684    "# It will only update dictionary and will not return anything"685   ]686  },687  {688   "cell_type": "code",689   "execution_count": 71,690   "id": "47911994",691   "metadata": {},692   "outputs": [693    {694     "name": "stdout",695     "output_type": "stream",696     "text": [697      "{'Karnataka': 'Banglore', 'Kerala': 'Trivindrum', 'Tamilnadu': 'Chennai', 'Telangana': 'Hyderabad', 'Maharastra': 'Mumbai', 'Madhya Pradesh': 'Bhopal', 'Andhra Pradesh': 'Vijayawada', 'Jharkand': 'Kolkata'}\n"698     ]699    }700   ],701   "source": [702    "print(states_and_capitals)"703   ]704  },705  {706   "cell_type": "code",707   "execution_count": 72,708   "id": "6a28e799",709   "metadata": {},710   "outputs": [711    {712     "data": {713      "text/plain": [714       "'Vijayawada'"715      ]716     },717     "execution_count": 72,718     "metadata": {},719     "output_type": "execute_result"720    }721   ],722   "source": [723    "states_and_capitals.setdefault('Andhra Pradesh','Ranchi')"724   ]725  },726  {727   "cell_type": "code",728   "execution_count": 73,729   "id": "a46f2eb8",730   "metadata": {},731   "outputs": [732    {733     "name": "stdout",734     "output_type": "stream",735     "text": [736      "{'Karnataka': 'Banglore', 'Kerala': 'Trivindrum', 'Tamilnadu': 'Chennai', 'Telangana': 'Hyderabad', 'Maharastra': 'Mumbai', 'Madhya Pradesh': 'Bhopal', 'Andhra Pradesh': 'Vijayawada', 'Jharkand': 'Kolkata'}\n"737     ]738    }739   ],740   "source": [741    "print(states_and_capitals)"742   ]743  },744  {745   "cell_type": "markdown",746   "id": "ec7d089d",747   "metadata": {},748   "source": [749    "### Creating dictionary from a list or set with a default value"750   ]751  },752  {753   "cell_type": "code",754   "execution_count": 76,755   "id": "3da122bf",756   "metadata": {},757   "outputs": [],758   "source": [759    "student_names = ['S1','S2','S3','S4']\n",760    "# Each element of list will be a key in the dictionary\n",761    "name_scores_di = dict.fromkeys(student_names,0)"762   ]763  },764  {765   "cell_type": "code",766   "execution_count": 75,767   "id": "3339b898",768   "metadata": {},769   "outputs": [770    {771     "name": "stdout",772     "output_type": "stream",773     "text": [774      "{'S1': 0, 'S2': 0, 'S3': 0, 'S4': 0}\n"775     ]776    }777   ],778   "source": [779    "print(name_scores_di)"780   ]781  },782  {783   "cell_type": "code",784   "execution_count": 78,785   "id": "7eb5fc0b",786   "metadata": {},787   "outputs": [],788   "source": [789    "name_scores_di['S1'] = 90"790   ]791  },792  {793   "cell_type": "code",794   "execution_count": 79,795   "id": "91fccab3",796   "metadata": {},797   "outputs": [798    {799     "data": {800      "text/plain": [801       "{'S1': 90, 'S2': 0, 'S3': 0, 'S4': 0}"802      ]803     },804     "execution_count": 79,805     "metadata": {},806     "output_type": "execute_result"807    }808   ],809   "source": [810    "name_scores_di"811   ]812  },813  {814   "cell_type": "code",815   "execution_count": 82,816   "id": "4d91ff4a",817   "metadata": {},818   "outputs": [],819   "source": [820    "name_scores_di['S2'] = 50"821   ]822  },823  {824   "cell_type": "code",825   "execution_count": 81,826   "id": "c7bf99d2",827   "metadata": {},828   "outputs": [],829   "source": [830    "name_scores_di['S1'] = 90\n",831    "name_scores_di['S2'] = 50"832   ]833  },834  {835   "cell_type": "markdown",836   "id": "6c03284b",837   "metadata": {},838   "source": [839    "### Understanding inbuilt function zip "840   ]841  },842  {843   "cell_type": "code",844   "execution_count": 131,845   "id": "a17d945c",846   "metadata": {},847   "outputs": [],848   "source": [849    "student_names = ['S1','S2','S3','S4']\n",850    "student_score = [90,25,56,32,55]"851   ]852  },853  {854   "cell_type": "code",855   "execution_count": 132,856   "id": "cfc566e5",857   "metadata": {},858   "outputs": [859    {860     "name": "stdout",861     "output_type": "stream",862     "text": [863      "[('S1', 90), ('S2', 25), ('S3', 56), ('S4', 32)]\n"864     ]865    }866   ],867   "source": [868    "print(list(zip(student_names,student_score)))"869   ]870  },871  {872   "cell_type": "code",873   "execution_count": 133,874   "id": "a6826c59",875   "metadata": {},876   "outputs": [877    {878     "data": {879      "text/plain": [880       "[['S1', 90], ['S2', 25], ['S3', 32], ['S4', 32]]"881      ]882     },883     "execution_count": 133,884     "metadata": {},885     "output_type": "execute_result"886    }887   ],888   "source": [889    "[['S1',90],['S2',25],['S3',32],['S4',32]]  ### Manually written equivalent of above code"890   ]891  },892  {893   "cell_type": "markdown",894   "id": "3ec6ac70",895   "metadata": {},896   "source": [897    "### Creating dictionary using two list as key and value"898   ]899  },900  {901   "cell_type": "code",902   "execution_count": 134,903   "id": "248eb102",904   "metadata": {},905   "outputs": [],906   "source": [907    "student_scores_2 = dict(zip(student_names,student_score))"908   ]909  },910  {911   "cell_type": "code",912   "execution_count": 135,913   "id": "a9752da6",914   "metadata": {},915   "outputs": [916    {917     "name": "stdout",918     "output_type": "stream",919     "text": [920      "{'S1': 90, 'S2': 25, 'S3': 56, 'S4': 32}\n"921     ]922    }923   ],924   "source": [925    "print(student_scores_2)"926   ]927  },928  {929   "cell_type": "markdown",930   "id": "0bf625de",931   "metadata": {},932   "source": [933    "### Understanding pop and popitems"934   ]935  },936  {937   "cell_type": "code",938   "execution_count": 136,939   "id": "ffc962be",940   "metadata": {},941   "outputs": [942    {943     "name": "stdout",944     "output_type": "stream",945     "text": [946      "{'S1': 90, 'S2': 25, 'S3': 56, 'S4': 32}\n"947     ]948    }949   ],950   "source": [951    "print(student_scores_2)"952   ]953  },954  {955   "cell_type": "code",956   "execution_count": 137,957   "id": "e10a2011",958   "metadata": {},959   "outputs": [960    {961     "data": {962      "text/plain": [963       "56"964      ]965     },966     "execution_count": 137,967     "metadata": {},968     "output_type": "execute_result"969    }970   ],971   "source": [972    "student_scores_2.pop('S3') ### Return the value of the specified key and remove that key value pair from the dictionary"973   ]974  },975  {976   "cell_type": "code",977   "execution_count": 138,978   "id": "b2fb6f66",979   "metadata": {},980   "outputs": [981    {982     "name": "stdout",983     "output_type": "stream",984     "text": [985      "{'S1': 90, 'S2': 25, 'S4': 32}\n"986     ]987    }988   ],989   "source": [990    "print(student_scores_2)"991   ]992  },993  {994   "cell_type": "code",995   "execution_count": 139,996   "id": "29947ea7",997   "metadata": {},998   "outputs": [999    {1000     "data": {1001      "text/plain": [1002       "('S4', 32)"1003      ]1004     },1005     "execution_count": 139,1006     "metadata": {},1007     "output_type": "execute_result"1008    }1009   ],1010   "source": [1011    "student_scores_2.popitem()"1012   ]1013  },1014  {1015   "cell_type": "code",1016   "execution_count": 140,1017   "id": "e6f47989",1018   "metadata": {},1019   "outputs": [1020    {1021     "name": "stdout",1022     "output_type": "stream",1023     "text": [1024      "{'S1': 90, 'S2': 25}\n"1025     ]1026    }1027   ],1028   "source": [1029    "print(student_scores_2)"1030   ]1031  },1032  {1033   "cell_type": "code",1034   "execution_count": 141,1035   "id": "bdbf65d0",1036   "metadata": {},1037   "outputs": [1038    {1039     "data": {1040      "text/plain": [1041       "('S2', 25)"1042      ]1043     },1044     "execution_count": 141,1045     "metadata": {},1046     "output_type": "execute_result"1047    }1048   ],1049   "source": [1050    "student_scores_2.popitem()"1051   ]1052  },1053  {1054   "cell_type": "code",1055   "execution_count": 142,1056   "id": "d9f36313",1057   "metadata": {},1058   "outputs": [1059    {1060     "name": "stdout",1061     "output_type": "stream",1062     "text": [1063      "{'S1': 90}\n"1064     ]1065    }1066   ],1067   "source": [1068    "print(student_scores_2)"1069   ]1070  },1071  {1072   "cell_type": "markdown",1073   "id": "7dbbde36",1074   "metadata": {},1075   "source": [1076    "### Tuple\n",1077    "- Ordered\n",1078    "- Immutable\n",1079    "- Heterogeneous\n",1080    "- Occupy less space on memory compared to list"1081   ]1082  },1083  {1084   "cell_type": "code",1085   "execution_count": 145,1086   "id": "e496cfae",1087   "metadata": {},1088   "outputs": [1089    {1090     "data": {1091      "text/plain": [1092       "tuple"1093      ]1094     },1095     "execution_count": 145,1096     "metadata": {},1097     "output_type": "execute_result"1098    }1099   ],1100   "source": [1101    "# Creating empty tuple  --- Not usefull\n",1102    "tu = ()\n",1103    "type(tu)"1104   ]1105  },1106  {1107   "cell_type": "code",1108   "execution_count": 150,1109   "id": "54a30006",1110   "metadata": {},1111   "outputs": [],1112   "source": [1113    "## Creating non - empty tuple\n",1114    "tu1 = (1,2,3,5,6,6,6)"1115   ]1116  },1117  {1118   "cell_type": "code",1119   "execution_count": 151,1120   "id": "c5abdaaf",1121   "metadata": {},1122   "outputs": [1123    {1124     "data": {1125      "text/plain": [1126       "tuple"1127      ]1128     },1129     "execution_count": 151,1130     "metadata": {},1131     "output_type": "execute_result"1132    }1133   ],1134   "source": [1135    "type(tu1)"1136   ]1137  },1138  {1139   "cell_type": "code",1140   "execution_count": 153,1141   "id": "9b211c4c",1142   "metadata": {},1143   "outputs": [1144    {1145     "data": {1146      "text/plain": [1147       "3"1148      ]1149     },1150     "execution_count": 153,1151     "metadata": {},1152     "output_type": "execute_result"1153    }1154   ],1155   "source": [1156    "### Count the occurances of the given element\n",1157    "tu1.count(6)"1158   ]1159  },1160  {1161   "cell_type": "code",1162   "execution_count": 156,1163   "id": "694ae94c",1164   "metadata": {},1165   "outputs": [1166    {1167     "data": {1168      "text/plain": [1169       "4"1170      ]1171     },1172     "execution_count": 156,1173     "metadata": {},1174     "output_type": "execute_result"1175    }1176   ],1177   "source": [1178    "### Gives the index of the first occurance of the given element\n",1179    "tu1.index(6)"1180   ]1181  },1182  {1183   "cell_type": "code",1184   "execution_count": 157,1185   "id": "b3ce502d",1186   "metadata": {},1187   "outputs": [1188    {1189     "ename": "ValueError",1190     "evalue": "tuple.index(x): x not in tuple",1191     "output_type": "error",1192     "traceback": [1193      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",1194      "\u001b[1;31mValueError\u001b[0m                                Traceback (most recent call last)",1195      "Input \u001b[1;32mIn [157]\u001b[0m, in \u001b[0;36m<cell line: 1>\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[0m \u001b[43mtu1\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mindex\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m89\u001b[39;49m\u001b[43m)\u001b[49m\n",1196      "\u001b[1;31mValueError\u001b[0m: tuple.index(x): x not in tuple"1197     ]1198    }1199   ],1200   "source": [

Showing the first 1,200 of 2141 lines. Download the file for the rest.