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 170fc9c commit 5de7a2c
Showing 1 changed file with 37 additions and 33 deletions.
70 changes: 37 additions & 33 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": 17,
"execution_count": 39,
"metadata": {},
"outputs": [
{
Expand All @@ -49,7 +49,7 @@
},
{
"cell_type": "code",
"execution_count": 18,
"execution_count": 40,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -83,7 +83,7 @@
},
{
"cell_type": "code",
"execution_count": 19,
"execution_count": 41,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -117,7 +117,7 @@
},
{
"cell_type": "code",
"execution_count": 20,
"execution_count": 42,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -160,7 +160,7 @@
},
{
"cell_type": "code",
"execution_count": 21,
"execution_count": 43,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -197,7 +197,7 @@
},
{
"cell_type": "code",
"execution_count": 22,
"execution_count": 44,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -225,7 +225,7 @@
},
{
"cell_type": "code",
"execution_count": 23,
"execution_count": 45,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -257,7 +257,7 @@
},
{
"cell_type": "code",
"execution_count": 24,
"execution_count": 46,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -296,7 +296,7 @@
},
{
"cell_type": "code",
"execution_count": 25,
"execution_count": 47,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -333,7 +333,7 @@
},
{
"cell_type": "code",
"execution_count": 26,
"execution_count": 48,
"metadata": {},
"outputs": [
{
Expand All @@ -342,18 +342,8 @@
"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'"
"After pop --> set()\n",
"Set is empty\n"
]
}
],
Expand Down Expand Up @@ -387,9 +377,18 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 49,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"my_set --> {'P', 'T', 'Q', 'R', 'S'}\n",
"Set after clear --> set()\n"
]
}
],
"source": [
"my_set = set(['P', 'Q', 'R', 'S','T' ])\n",
"print (\"my_set -->\", my_set)\n",
Expand All @@ -407,17 +406,22 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 50,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Set after delete --> set()\n"
]
}
],
"source": [
"my_set = set([1,2,3,4,5 ])\n",
"print (\"my_set -->\", my_set)\n",
"\n",
"del my_set\n",
"print (\"Set after delete -->\", my_set) # Error\n",
" # Set is deleted and still want to print\n",
" # Exception should me handle\n"
"try:\n",
" print(\"Set after delete -->\", my_set)\n",
"except NameError:\n",
" print(\"Set is deleted and cannot be printed.\")\n"
]
},
{
Expand Down

0 comments on commit 5de7a2c

Please sign in to comment.