1+ # List, Tuple & Set
2+ thislist = ["apple" , "banana" ]
3+
4+ #basic print
5+ print (thislist [- 1 ])
6+ #banana
7+ print (thislist [0 :2 ])
8+ #['apple', 'banana']
9+ print (thislist [0 :])
10+ #['apple', 'banana']
11+
12+ #add
13+ thislist .insert (9 , "watermelon" )
14+ print (thislist )
15+ #['apple', 'banana', 'watermelon']
16+ thislist .append ("cherry" )
17+ print (thislist )
18+ #['apple', 'banana', 'watermelon', 'cherry']
19+
20+ #extend
21+ tropical = ["pineapple" , "papaya" ]
22+ thislist .extend (tropical )
23+ print (thislist )
24+ #['apple', 'banana', 'watermelon', 'cherry', 'pineapple', 'papaya']
25+
26+ #remove
27+ thislist .remove ("banana" )
28+ print (thislist )
29+ #['apple', 'watermelon', 'cherry', 'pineapple', 'papaya']
30+ thislist .clear ()
31+ print (thislist )
32+ #[]
33+
34+ #more
35+ thislist = ["apple" , "banana" , "cherry" ]
36+ for x in thislist :
37+ print (x )
38+ #apple
39+ #banana
40+ #cherry
41+ i = 0
42+ while i < len (thislist ):
43+ print (thislist [i ])
44+ i = i + 1
45+ #apple
46+ #banana
47+ #cherry
48+
49+ #sort
50+ thislist = [100 , 50 , 65 , 82 , 23 ]
51+ thislist .sort (reverse = True )
52+ print (thislist )
53+ #[100, 82, 65, 50, 23]
54+
55+ #copy list
56+ thislist = ["apple" , "banana" , "cherry" ]
57+ mylist = thislist .copy ()
58+ print (mylist )
59+
60+ #join list
61+ list1 = ["a" , "b" , "c" ]
62+ list2 = [1 , 2 , 3 ]
63+ list3 = list1 + list2
64+ print (list3 )
65+ #['a', 'b', 'c', 1, 2, 3]
66+
67+
68+ # Tuples(Cant be changed)
69+ thistuple = ("apple" , "banana" , "cherry" )
70+ print (thistuple )
71+ #('apple', 'banana', 'cherry')
72+ print (len (thistuple ))
73+ #3
74+ print (thistuple [1 ])
75+ #banana
76+
77+ #remove
78+ thistuple = ("apple" , "banana" , "cherry" )
79+ y = list (thistuple )
80+ y .remove ("apple" )
81+ thistuple = tuple (y )
82+ print (thistuple )
83+
84+ #multiply tuple
85+ fruits = ("apple" )
86+ mytuple = fruits * 2
87+ print (mytuple )
88+ #appleapple
89+
90+ #intersection
91+ x = {"apple" , "banana" , "cherry" }
92+ y = {"google" , "microsoft" , "apple" }
93+ x .intersection_update (y )
94+ print (x )
95+ #{'apple'}
0 commit comments