-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlist.py
More file actions
35 lines (34 loc) · 1.26 KB
/
list.py
File metadata and controls
35 lines (34 loc) · 1.26 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
#List
l = [10, 20, 30, 40, 50]
print(l) #print list
print(l[3]) #print item at index 3
print(l[-1]) #print last item
print(l[-2]) #print second last item
l.append(30) #append item 30 at end of list
print(l)
l.insert(1, 15) #15 is going to instered at index 1 and item from index 1 going to shift to right side
print(l)
print (15 in l) #in operator to check item present in the collection
print (l.count(30)) # count the occurance of an item in collection
print (l.index(30)) #index function tell the first occurance of item.
print (l.index(30,4,7)) #index search between 4 to 7
l.remove(20) #remove value
print(l)
print(l.pop()) #remove the last value and reture the removed value
print(l)
print(l.pop(2)) #remove item at index 2 and return the value at index 2
print (l)
del l[1] #remove item at index 1
print (l)
del l[0:2] #remove item at index 0 and 1
print (l)
#l = [10, 40, 20, 50]
l = ["aditya", "anived", "abhishek"]
print (l)
print (max(l))
print (min(l))
#print (sum(l))
l.reverse()
print(l)
l.sort() #sort the listin creasing order
print(l)