Skip to content

Commit 4a4099a

Browse files
committed
Add tuple and set.
1 parent 3486939 commit 4a4099a

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

data_structures/set/set_example.py

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
colors = {'white', 'black', 'red', 'blue', 'yellow', 'white', 'red'}
2+
print(colors) # duplicates have been removed.
3+
4+
# testing
5+
t = 'black' in colors
6+
print(t)
7+
t = 'pink' in colors
8+
print(t)

data_structures/set/set_operation.py

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
s = set('abcdabcde')
2+
t = set('qazqazw')
3+
e = set() # empty set
4+
5+
print(s)
6+
print(t)
7+
print(e)
8+
9+
print(s | t)
10+
print(s & t)
11+
print(s - t)
12+
print(s ^ t)

data_structures/tuple/tuple.py

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
t1 = 10, 20, 30, 40 # separate by commas to make tuple.
2+
3+
print(t1[0]) # also index can be used.
4+
print(t1) # tuple should be printed with `()`.
5+
6+
t2 = t1, (100, 200) # nesting
7+
print(t2)
8+
print(t2[0])
9+
#t2[0][1] = 0 # tuples are immutable

0 commit comments

Comments
 (0)