-
Notifications
You must be signed in to change notification settings - Fork 0
/
ListFun.py
55 lines (54 loc) · 1.05 KB
/
ListFun.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
#List related functions
l=list(range(0,15))#list created using range
print(l)
for x in l:
print(x,end=" ")#accessing list element using for loop
print()
#length of string
print(len(l))
#number of occurences of each object
print(l.count(10))
#index of a object
print(l.index(10))#if element is not in the list it gives error
#print(l.index(100))
#finding the object is present or not in the list
##t=int(input("Enter target to be found"))
##if t in l:
## print("Given target is in list",(l.index(t)))
##else:
## print("Target not found in list at index ")
nl=[]
#appending elements in the list
nl.append(100)
nl.append(200)
nl.append(300)
nl.append(400)
nl.append(500)
print(nl)
a=[]
v=1000
for i in range(0,11):
a.append(v)
v+=100
print(a)
#use of insert function
a.insert(100,19)
print(a)
a.insert(-100,19)
print(a)
#use of extend function
a.extend(l)
print(a)
a.extend((1,2,3,4))
print(a)
#use of remove method
a1=[10,20,30]
print(a1)
a1.remove(20)
print(a1)
#use of pop method
print(a1.pop(1))
print(a1)
r=[100,200,300,400,900]
(r.reverse())
print(r)