This repository was archived by the owner on Dec 27, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path4. List-Touple-Set.py
More file actions
95 lines (82 loc) · 1.64 KB
/
4. List-Touple-Set.py
File metadata and controls
95 lines (82 loc) · 1.64 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# List, Tuple & Set
thislist = ["apple", "banana"]
#basic print
print(thislist[-1])
#banana
print(thislist[0:2])
#['apple', 'banana']
print(thislist[0:])
#['apple', 'banana']
#add
thislist.insert(9, "watermelon")
print(thislist)
#['apple', 'banana', 'watermelon']
thislist.append("cherry")
print(thislist)
#['apple', 'banana', 'watermelon', 'cherry']
#extend
tropical = ["pineapple", "papaya"]
thislist.extend(tropical)
print(thislist)
#['apple', 'banana', 'watermelon', 'cherry', 'pineapple', 'papaya']
#remove
thislist.remove("banana")
print(thislist)
#['apple', 'watermelon', 'cherry', 'pineapple', 'papaya']
thislist.clear()
print(thislist)
#[]
#more
thislist = ["apple", "banana", "cherry"]
for x in thislist:
print(x)
#apple
#banana
#cherry
i = 0
while i < len(thislist):
print(thislist[i])
i = i + 1
#apple
#banana
#cherry
#sort
thislist = [100, 50, 65, 82, 23]
thislist.sort(reverse = True)
print(thislist)
#[100, 82, 65, 50, 23]
#copy list
thislist = ["apple", "banana", "cherry"]
mylist = thislist.copy()
print(mylist)
#join list
list1 = ["a", "b", "c"]
list2 = [1, 2, 3]
list3 = list1 + list2
print(list3)
#['a', 'b', 'c', 1, 2, 3]
# Tuples(Cant be changed)
thistuple = ("apple", "banana", "cherry")
print(thistuple)
#('apple', 'banana', 'cherry')
print(len(thistuple))
#3
print(thistuple[1])
#banana
#remove
thistuple = ("apple", "banana", "cherry")
y = list(thistuple)
y.remove("apple")
thistuple = tuple(y)
print(thistuple)
#multiply tuple
fruits = ("apple")
mytuple = fruits * 2
print(mytuple)
#appleapple
#intersection
x = {"apple", "banana", "cherry"}
y = {"google", "microsoft", "apple"}
x.intersection_update(y)
print(x)
#{'apple'}