-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdata_structure.py
71 lines (60 loc) · 1.3 KB
/
data_structure.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# I'm going to use list and its methods
from collections import deque
# creating a empty list
lst_one = []
# creating a list with items
lst_two = [1, 2, 3, 4, 5, 6]
lst_two.append(12)
print(lst_two)
lst_two.extend([13,14,15,16])
print(lst_two)
lst_two.remove(2)
print(lst_two)
print(lst_two.pop(0)) # remove the item with position (x) and return this item
print(lst_two)
print(lst_two.index(13))
lst_two.insert(7, 15)
lst_two.insert(7, 15)
print(lst_two)
print(lst_two.count(15))
# reverse the list
lst_two.reverse()
print(lst_two)
# other list
lst_three = [{"name":'Tom', "age":20, "city": 'california'}]
print(lst_three)
print("-"*30)
# USING LISTS AS STACKS
print("STACKS")
stack_one = [1, 1, 2, 3, 5, 8, 13, 21, 34]
print(stack_one)
stack_one.append(45)
stack_one.append(79)
stack_one.append(124)
stack_one.append(203)
stack_one.append(327)
print(stack_one)
stack_one.pop()
stack_one.pop()
stack_one.pop()
stack_one.pop()
print(stack_one)
print("-"*30)
# USING LISTS AS QUEUES
# we need to import deque from collections
print("QUEUES")
queues = deque([1, 1, 2, 3, 5, 8, 13, 21, 34, 45])
print(queues)
queues.append(79)
queues.append(124)
queues.append(203)
queues.append(327)
print(queues)
queues.popleft()
queues.popleft()
queues.popleft()
queues.popleft()
queues.popleft()
queues.popleft()
print(queues)
print("-"*30)