forked from BoldAndGenius/A18-M2-Force
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcollection_methods.py
204 lines (160 loc) · 5.15 KB
/
collection_methods.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
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
#################################################################################
#################################################################################
'''LIST METHODS'''
#append
watches = ["rolex", "fastract", "fossil", "titan", "casio"]
watches.append("sonata")
print(watches)
#copy
watches_copy = watches.copy()
print(watches_copy)
#clear
watches_copy.clear()
print(watches_copy)
#count
shoes = ["nike", "Puma", "adidas", "woodland", "puma"]
result = shoes.count("bata")
print(result)
#remove
countries = ["switzerland", "pakistan", "india", "usa", "russia", "pakistan"]
countries.remove("pakistan")
print(countries)
#insert
my_cartoons = ["tom and jerry", "doraemon", "ninja hattori", "spongebob", "pink panther"]
my_cartoons.insert(0, "noddy")
print(my_cartoons)
#extend
your_cartoons = ["ben 10", "shinchan", "chota bheem", "motupatlu", "oggy"]
my_cartoons.extend(your_cartoons)
print(my_cartoons)
my_cartoons.extend("micky") #char by char
print(my_cartoons)
#pop
superheroes = ["ironman", "jai baalayya", "shaktimaan", "black panther", "deadpool"]
result = superheroes.pop()
print(result)
print(superheroes)
result = superheroes.pop(2)
print(result)
print(superheroes)
#index
animes = ["AOT", "one piece", "demon slayer", "death note", "DBZ", "naruto", "tokyo ghoul", "iq"]
result = animes.index("DBZ", 0, 3)
print(result)
#reverse
supervillains = ["thanos", "doctor doom", "hella", "rolex", "homelander","joker"]
supervillains.reverse()
print(supervillains)
#sort
bands = ["1D", "bts", "blackpink", "maroon 5", "imagine dragons"]
bands.sort()
print(bands)
##################################################################################
##################################################################################
'''TUPLE METHODS'''
#count
drinks = "j&d", "teachers", "old monk", "imperial blue", "blenders pride", "vat69"
result = drinks.count("old monk")
print(result)
print(type(drinks))
#index
companies = ("google", "facebook", "ms", "wipro", "amazon", "ibm", "tata")
result = companies.index("ibm")
print(result)
###################################################################################
###################################################################################
'''SET METHODS'''
#add
supercars = {"lambo", "bugatti", "porsche","ferrari", "bujji", "mustang", "ferrari"}
supercars.add("aston martin")
print(supercars)
#copy
supercars_copy = supercars.copy()
print(supercars_copy)
supercars_copy.clear()
print(supercars_copy)
games1 = {"gta", "far cry", "god of war", "assassins creed"}
games2 = {"fifa", "cricket 2007", "mario", "gta", "free fire"}
#union
result = games1.union(games2)
print(result)
#intersection
result = games1.intersection(games2)
print(result)
#difference
result = games1.difference(games2)
print(result)
#symmetric_difference
result = games1.symmetric_difference(games2)
print(result)
#remove
fruits = {"mango", "strawberry", "apple", "pomogranate", "orange", "grapes"}
fruits.remove("dragon fruit") #error
print(fruits)
#discard
fruits.discard("dragon fruit")
print(fruits)
print("tata")
#pop
junkfoodchains = {"kfc", "mcd", "dominoes", "bk", "pizzahut", "tacobell"}
result = junkfoodchains.pop()
print(result)
print(junkfoodchains)
#update/ intersection_update/ difference_update/ symmetric_difference_update
set1 = {10, 20, 30}
set2 = {30, 40, 50}
set1.update(set2)
set1.intersection_update(set2)
set1.difference_update(set2)
set1.symmetric_difference_update(set2)
print(set1)
#issubset/ issuperset/ isdisjoint
set1 = {1, 2, 3, 4, 5}
set2 = {3, 4}
result = set1.issubset(set2) #False
result = set1.issuperset(set2)
result = set1.isdisjoint(set2)
print(result)
###################################################################################
###################################################################################
'''DICTIONARY METHODS'''
#copy
movie1 = {"name":"baahubali", "cast":("prabhas", "sweety", "raana"), "budget":250, "music":"keervani", "director":"raajmouli"}
movie1_copy = movie1.copy()
print(movie1_copy)
#clear
movie1_copy.clear()
print(movie1_copy) #{}
#keys
result = movie1.keys()
print(result)
#values
result = movie1.values()
print(result)
#items
result = movie1.items()
print(result)
movie1["language"] = "telugu"
print(movie1["language"])
#pop
result = movie1.pop("language")
print(result)
#popitem
result = movie1.popitem()
print(result)
print(movie1)
#update
movie1 = {"cast":("prabhas", "sweety", "raana"), "budget":250, "music":"keervani", "director":"raajmouli"}
extra_info = {"songs":["saahore baahubali", "mamathala thalli"], "duration":3}
movie1.update(extra_info)
print(movie1)
#setdefault
result = movie1.setdefault("name", "bb")
print(result)
#fromkeys
planets = ["mercury", "venus", "earth", "mars", "jupitar", "saturn", "uranus", "neptune"]
dict1 = {}
result = dict1.fromkeys(planets, "sun")
print(result)
#####################################################################################
#####################################################################################