Skip to content

Commit

Permalink
python set fix
Browse files Browse the repository at this point in the history
  • Loading branch information
slayerrr12 committed Jan 15, 2024
1 parent 80b666f commit 170fc9c
Showing 1 changed file with 59 additions and 30 deletions.
89 changes: 59 additions & 30 deletions BasicPython/Sets IN python/Python_Set.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 17,
"metadata": {},
"outputs": [
{
Expand All @@ -49,7 +49,7 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 18,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -83,7 +83,7 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": 19,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -117,7 +117,7 @@
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": 20,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -160,7 +160,7 @@
},
{
"cell_type": "code",
"execution_count": 13,
"execution_count": 21,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -197,7 +197,7 @@
},
{
"cell_type": "code",
"execution_count": 14,
"execution_count": 22,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -225,7 +225,7 @@
},
{
"cell_type": "code",
"execution_count": 15,
"execution_count": 23,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -257,7 +257,7 @@
},
{
"cell_type": "code",
"execution_count": 16,
"execution_count": 24,
"metadata": {},
"outputs": [
{
Expand All @@ -266,18 +266,8 @@
"text": [
"my_set --> {'P', 'T', 'Q', 'R', 'S'}\n",
"After removing (P) --> {'T', 'Q', 'R', 'S'}\n",
"After removing (Q) --> {'T', 'R', 'S'}\n"
]
},
{
"ename": "KeyError",
"evalue": "'Q'",
"output_type": "error",
"traceback": [
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[1;31mKeyError\u001b[0m Traceback (most recent call last)",
"Cell \u001b[1;32mIn[16], line 10\u001b[0m\n\u001b[0;32m 7\u001b[0m my_set \u001b[38;5;241m.\u001b[39mremove(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mQ\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[0;32m 8\u001b[0m \u001b[38;5;28mprint\u001b[39m (\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mAfter removing (Q) -->\u001b[39m\u001b[38;5;124m\"\u001b[39m, my_set )\n\u001b[1;32m---> 10\u001b[0m \u001b[43mmy_set\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mremove\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mQ\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m)\u001b[49m \u001b[38;5;66;03m# Error\u001b[39;00m\n\u001b[0;32m 11\u001b[0m \u001b[38;5;28mprint\u001b[39m (\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mAfter Adding (Q) -->\u001b[39m\u001b[38;5;124m\"\u001b[39m, my_set )\n",
"\u001b[1;31mKeyError\u001b[0m: 'Q'"
"After removing (Q) --> {'T', 'R', 'S'}\n",
"After Adding (Q) --> {'T', 'R', 'S'}\n"
]
}
],
Expand Down Expand Up @@ -306,9 +296,20 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 25,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"my_set --> {'P', 'T', 'Q', 'R', 'S'}\n",
"After discard (P) --> {'T', 'Q', 'R', 'S'}\n",
"After discard (Q) --> {'T', 'R', 'S'}\n",
"After discard (Q) --> {'T', 'R', 'S'}\n"
]
}
],
"source": [
"my_set = set(['P', 'Q', 'Q','R', 'S', \"T\" ])\n",
"print (\"my_set -->\", my_set)\n",
Expand All @@ -332,21 +333,49 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 26,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"my_set --> {'A', 'B'}\n",
"After pop --> {'B'}\n",
"After pop --> set()\n"
]
},
{
"ename": "KeyError",
"evalue": "'pop from an empty set'",
"output_type": "error",
"traceback": [
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[1;31mKeyError\u001b[0m Traceback (most recent call last)",
"Cell \u001b[1;32mIn[26], line 10\u001b[0m\n\u001b[0;32m 7\u001b[0m my_set\u001b[38;5;241m.\u001b[39mpop()\n\u001b[0;32m 8\u001b[0m \u001b[38;5;28mprint\u001b[39m (\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mAfter pop -->\u001b[39m\u001b[38;5;124m\"\u001b[39m, my_set)\n\u001b[1;32m---> 10\u001b[0m \u001b[43mmy_set\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mpop\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m \u001b[38;5;66;03m# Error; Set is empty; Under flow\u001b[39;00m\n\u001b[0;32m 11\u001b[0m \u001b[38;5;28mprint\u001b[39m (\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mAfter pop -->\u001b[39m\u001b[38;5;124m\"\u001b[39m, my_set)\n",
"\u001b[1;31mKeyError\u001b[0m: 'pop from an empty set'"
]
}
],
"source": [
"my_set = set(['A', 'B' ])\n",
"print (\"my_set -->\", my_set)\n",
"\n",
"my_set.pop()\n",
"print (\"After pop -->\", my_set)\n",
"if my_set:\n",
" my_set.pop()\n",
" print (\"After pop -->\", my_set)\n",
"\n",
"my_set.pop()\n",
"print (\"After pop -->\", my_set)\n",
"if my_set:\n",
" my_set.pop()\n",
" print (\"After pop -->\", my_set)\n",
"else:\n",
" print(\"Set is empty\")\n",
"\n",
"my_set.pop() # Error; Set is empty; Under flow\n",
"print (\"After pop -->\", my_set)"
"if my_set:\n",
" my_set.pop()\n",
" print (\"After pop -->\", my_set)\n",
"else:\n",
" print(\"Set is empty\")\n"
]
},
{
Expand Down

0 comments on commit 170fc9c

Please sign in to comment.