Skip to content

Commit e1e385e

Browse files
committed
Sets
1 parent a8d0ba8 commit e1e385e

File tree

5 files changed

+242
-7
lines changed

5 files changed

+242
-7
lines changed

Diff for: .ipynb_checkpoints/07.Sets-checkpoint.ipynb

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"cells": [],
3+
"metadata": {},
4+
"nbformat": 4,
5+
"nbformat_minor": 2
6+
}

Diff for: .ipynb_checkpoints/Untitled-checkpoint.ipynb

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"cells": [],
3+
"metadata": {},
4+
"nbformat": 4,
5+
"nbformat_minor": 2
6+
}

Diff for: 06.Tuple.ipynb

+67-7
Original file line numberDiff line numberDiff line change
@@ -259,27 +259,87 @@
259259
},
260260
{
261261
"cell_type": "code",
262-
"execution_count": 20,
262+
"execution_count": 21,
263263
"metadata": {},
264264
"outputs": [
265265
{
266-
"ename": "TypeError",
267-
"evalue": "'tuple' object does not support item assignment",
266+
"ename": "NameError",
267+
"evalue": "name 'thistuple' is not defined",
268268
"output_type": "error",
269269
"traceback": [
270270
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
271-
"\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)",
272-
"\u001b[0;32m<ipython-input-20-fe88f2910dbf>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0mthistuple\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0;34m\"apple\"\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m\"banana\"\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m\"cherry\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m \u001b[0mthistuple\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m3\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m\"orange\"\u001b[0m \u001b[0;31m# This will raise an error\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 3\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mthistuple\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
273-
"\u001b[0;31mTypeError\u001b[0m: 'tuple' object does not support item assignment"
271+
"\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)",
272+
"\u001b[0;32m<ipython-input-21-7255dda8a7d6>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0mthistuple\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0;34m\"apple\"\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m\"banana\"\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m\"cherry\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 2\u001b[0m \u001b[0;32mdel\u001b[0m \u001b[0mthistuple\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 3\u001b[0;31m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mthistuple\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
273+
"\u001b[0;31mNameError\u001b[0m: name 'thistuple' is not defined"
274274
]
275275
}
276276
],
277277
"source": [
278278
"thistuple = (\"apple\", \"banana\", \"cherry\")\n",
279-
"thistuple[3] = \"orange\" # This will raise an error\n",
279+
"del thistuple\n",
280+
"print(thistuple)"
281+
]
282+
},
283+
{
284+
"cell_type": "code",
285+
"execution_count": 23,
286+
"metadata": {},
287+
"outputs": [
288+
{
289+
"name": "stdout",
290+
"output_type": "stream",
291+
"text": [
292+
"('apple', 'banana', 'cherry')\n"
293+
]
294+
}
295+
],
296+
"source": [
297+
"thistuple = tuple((\"apple\", \"banana\", \"cherry\")) \n",
280298
"print(thistuple)"
281299
]
282300
},
301+
{
302+
"cell_type": "code",
303+
"execution_count": 24,
304+
"metadata": {},
305+
"outputs": [
306+
{
307+
"name": "stdout",
308+
"output_type": "stream",
309+
"text": [
310+
"3\n"
311+
]
312+
}
313+
],
314+
"source": [
315+
"thistuple = (1, 3, 7, 8, 7, 5, 4, 6, 8, 5)\n",
316+
"\n",
317+
"x = thistuple.index(8)\n",
318+
"\n",
319+
"print(x) "
320+
]
321+
},
322+
{
323+
"cell_type": "code",
324+
"execution_count": 25,
325+
"metadata": {},
326+
"outputs": [
327+
{
328+
"name": "stdout",
329+
"output_type": "stream",
330+
"text": [
331+
"2\n"
332+
]
333+
}
334+
],
335+
"source": [
336+
"thistuple = (1, 3, 7, 8, 7, 5, 4, 6, 8, 5)\n",
337+
"\n",
338+
"x = thistuple.count(5)\n",
339+
"\n",
340+
"print(x) "
341+
]
342+
},
283343
{
284344
"cell_type": "code",
285345
"execution_count": null,

Diff for: 07.Sets.ipynb

+157
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 1,
6+
"metadata": {},
7+
"outputs": [
8+
{
9+
"name": "stdout",
10+
"output_type": "stream",
11+
"text": [
12+
"{1, 2, 3}\n"
13+
]
14+
}
15+
],
16+
"source": [
17+
"my_set = {1, 2, 3}\n",
18+
"print(my_set)"
19+
]
20+
},
21+
{
22+
"cell_type": "code",
23+
"execution_count": 2,
24+
"metadata": {},
25+
"outputs": [
26+
{
27+
"name": "stdout",
28+
"output_type": "stream",
29+
"text": [
30+
"{1.0, 'Hello', (1, 2, 3)}\n"
31+
]
32+
}
33+
],
34+
"source": [
35+
"my_set = {1.0, \"Hello\", (1, 2, 3)}\n",
36+
"print(my_set)"
37+
]
38+
},
39+
{
40+
"cell_type": "code",
41+
"execution_count": 3,
42+
"metadata": {},
43+
"outputs": [
44+
{
45+
"name": "stdout",
46+
"output_type": "stream",
47+
"text": [
48+
"{1, 2, 3, 4}\n"
49+
]
50+
}
51+
],
52+
"source": [
53+
"my_set = {1,2,3,4,3,2}\n",
54+
"print(my_set)"
55+
]
56+
},
57+
{
58+
"cell_type": "code",
59+
"execution_count": 4,
60+
"metadata": {},
61+
"outputs": [
62+
{
63+
"name": "stdout",
64+
"output_type": "stream",
65+
"text": [
66+
"{1, 2, 3}\n"
67+
]
68+
}
69+
],
70+
"source": [
71+
"my_set = set([1,2,3,2])\n",
72+
"print(my_set)"
73+
]
74+
},
75+
{
76+
"cell_type": "code",
77+
"execution_count": 5,
78+
"metadata": {},
79+
"outputs": [
80+
{
81+
"name": "stdout",
82+
"output_type": "stream",
83+
"text": [
84+
"<class 'set'>\n"
85+
]
86+
}
87+
],
88+
"source": [
89+
"print(type(my_set))"
90+
]
91+
},
92+
{
93+
"cell_type": "code",
94+
"execution_count": 6,
95+
"metadata": {},
96+
"outputs": [
97+
{
98+
"name": "stdout",
99+
"output_type": "stream",
100+
"text": [
101+
"{1, 2, 3}\n"
102+
]
103+
}
104+
],
105+
"source": [
106+
"my_set.add(2)\n",
107+
"print(my_set)"
108+
]
109+
},
110+
{
111+
"cell_type": "code",
112+
"execution_count": 7,
113+
"metadata": {},
114+
"outputs": [
115+
{
116+
"name": "stdout",
117+
"output_type": "stream",
118+
"text": [
119+
"{1, 2, 3, 4}\n"
120+
]
121+
}
122+
],
123+
"source": [
124+
"my_set.update([2,3,4])\n",
125+
"print(my_set)"
126+
]
127+
},
128+
{
129+
"cell_type": "code",
130+
"execution_count": null,
131+
"metadata": {},
132+
"outputs": [],
133+
"source": []
134+
}
135+
],
136+
"metadata": {
137+
"kernelspec": {
138+
"display_name": "Python 3",
139+
"language": "python",
140+
"name": "python3"
141+
},
142+
"language_info": {
143+
"codemirror_mode": {
144+
"name": "ipython",
145+
"version": 3
146+
},
147+
"file_extension": ".py",
148+
"mimetype": "text/x-python",
149+
"name": "python",
150+
"nbconvert_exporter": "python",
151+
"pygments_lexer": "ipython3",
152+
"version": "3.7.3"
153+
}
154+
},
155+
"nbformat": 4,
156+
"nbformat_minor": 2
157+
}

Diff for: Untitled.ipynb

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"cells": [],
3+
"metadata": {},
4+
"nbformat": 4,
5+
"nbformat_minor": 2
6+
}

0 commit comments

Comments
 (0)