-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdataStructure.py
More file actions
53 lines (42 loc) · 1.29 KB
/
Copy pathdataStructure.py
File metadata and controls
53 lines (42 loc) · 1.29 KB
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
# List [] = mutable, most flexible
# Tuple () = immutable, faster
# Set {} = mutable (add/remove), unordered
# No duplicates, best for membership testing
#LIST
print("\nLIST")
print("==========================================")
fruits = ["apple", "orange", "banana", "coconut"]
print(fruits) #Print out whole List
fruits[0] = "Lemon" #Updating the element
fruits.remove("banana") #Removing specific element
fruits.append("cherry") #Appending or add element
fruits.insert(1, "banana") #Inserting the element at specific i
fruits.pop(2) #removing the element at specific element
fruits.clear() #Cleaning all of elements
#Print out list using the loop
for fruit in fruits:
print(fruit, end=" ")
#TUPLE !Immutable
print("\nTUPLE")
print("==========================================")
fruits = ("apple", "orange", "banana", "coconut")
for fruit in fruits:
print(fruit, end=" ")
#SET !Unordered
print("\nSET")
print("==========================================")
fruits = {"apple", "orange", "banana", "coconut"}
fruits.add("mango")
fruits.add("mango")
fruits.add("mango")
fruits.remove("coconut")
fruits.pop()
print(fruits)
fruits.clear()
for fruit in fruits:
print(fruit, end=" ")
#Search for specific element in set
if "banana" in fruits:
print("banana found")
else:
print("banana not found")