Skip to content

Commit fd073a3

Browse files
committed
Added set methods
1 parent a7f1c27 commit fd073a3

1 file changed

Lines changed: 139 additions & 0 deletions

File tree

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"source": [
6+
"Set Operations\r\n",
7+
"---------------"
8+
],
9+
"metadata": {}
10+
},
11+
{
12+
"cell_type": "code",
13+
"execution_count": 1,
14+
"source": [
15+
"set_1 = {1,2,3,4}\r\n",
16+
"set_2 = {3,4,5,6}\r\n"
17+
],
18+
"outputs": [],
19+
"metadata": {}
20+
},
21+
{
22+
"cell_type": "code",
23+
"execution_count": 3,
24+
"source": [
25+
"# union operation\r\n",
26+
"print(set_1 | set_2)\r\n",
27+
"print(set_1.union(set_2))"
28+
],
29+
"outputs": [
30+
{
31+
"output_type": "stream",
32+
"name": "stdout",
33+
"text": [
34+
"{1, 2, 3, 4, 5, 6}\n",
35+
"{1, 2, 3, 4, 5, 6}\n"
36+
]
37+
}
38+
],
39+
"metadata": {}
40+
},
41+
{
42+
"cell_type": "code",
43+
"execution_count": 4,
44+
"source": [
45+
"# intersection\r\n",
46+
"print(set_1 & set_2)\r\n",
47+
"print(set_1.intersection(set_2))"
48+
],
49+
"outputs": [
50+
{
51+
"output_type": "stream",
52+
"name": "stdout",
53+
"text": [
54+
"{3, 4}\n",
55+
"{3, 4}\n"
56+
]
57+
}
58+
],
59+
"metadata": {}
60+
},
61+
{
62+
"cell_type": "code",
63+
"execution_count": 5,
64+
"source": [
65+
"# difference\r\n",
66+
"print(set_1 - set_2)\r\n",
67+
"print(set_1.difference(set_2))"
68+
],
69+
"outputs": [
70+
{
71+
"output_type": "stream",
72+
"name": "stdout",
73+
"text": [
74+
"{1, 2}\n",
75+
"{1, 2}\n"
76+
]
77+
}
78+
],
79+
"metadata": {}
80+
},
81+
{
82+
"cell_type": "code",
83+
"execution_count": 7,
84+
"source": [
85+
"# is subset\r\n",
86+
"set_3 = {1,2,3}\r\n",
87+
"set_4 = { 1,2,3,4,5}\r\n",
88+
"print(set_3.issubset(set_4))\r\n",
89+
"print(set_3 <= set_4)"
90+
],
91+
"outputs": [
92+
{
93+
"output_type": "stream",
94+
"name": "stdout",
95+
"text": [
96+
"True\n",
97+
"True\n"
98+
]
99+
}
100+
],
101+
"metadata": {}
102+
},
103+
{
104+
"cell_type": "code",
105+
"execution_count": null,
106+
"source": [
107+
"# is superset\r\n",
108+
"print(set_4.issuperset(set_3))\r\n",
109+
"print(set_4 >= set_3)"
110+
],
111+
"outputs": [],
112+
"metadata": {}
113+
}
114+
],
115+
"metadata": {
116+
"orig_nbformat": 4,
117+
"language_info": {
118+
"name": "python",
119+
"version": "3.9.4",
120+
"mimetype": "text/x-python",
121+
"codemirror_mode": {
122+
"name": "ipython",
123+
"version": 3
124+
},
125+
"pygments_lexer": "ipython3",
126+
"nbconvert_exporter": "python",
127+
"file_extension": ".py"
128+
},
129+
"kernelspec": {
130+
"name": "python3",
131+
"display_name": "Python 3.9.4 64-bit"
132+
},
133+
"interpreter": {
134+
"hash": "63fd5069d213b44bf678585dea6b12cceca9941eaf7f819626cde1f2670de90d"
135+
}
136+
},
137+
"nbformat": 4,
138+
"nbformat_minor": 2
139+
}

0 commit comments

Comments
 (0)