-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path#17 List_Method.py
More file actions
64 lines (50 loc) · 1.42 KB
/
#17 List_Method.py
File metadata and controls
64 lines (50 loc) · 1.42 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
#so we already talked about String methods so i think its no need to explain about list methods
#so lets take a look at few methods
numbers = [9,2,5,7,9,4.9]
val = [50,654,3258,14,785,1235]
#append
numbers.append(50)
print(numbers)
#insert
#we can use this method to insert items into middle
#and this method takes 2 parameters first one is the index of item that should add your number
numbers.insert(1,20)
print(numbers)
#remove
#this method directly take the value that we want to remove so we dont need to pass index
numbers.remove(7)
print(numbers)
#reverse
#this method will rearange order of the items end to start
numbers.reverse()
print(numbers)
#pop
#with this we can remove last item of a list
numbers.pop()
print(numbers)
#index
#using this method we can get index of an item
print(numbers.index(2))
#and we also can check the existance of a item
print(50 in numbers)
#count
#this method will give count of value that we pass in
print(numbers.count(9))
#sort
#this method will sort items in the list in ascending order
numbers.sort()
print(numbers)
#and we can sort it descending order by using simple trick
print(val)
val.sort()
val.reverse()
print(val)
#copy
#using this method we can simply copy a list
num2 = numbers.copy()
#clear
#using this method we can clear a entire list
num2.clear()
print(num2)
#so these are the methods that can perform on a list
### write a programm to remove duplicates of a list