List
List
EXAMPLE
Forward indexing
0 1 2 3 4 5 6 7
7 5 9 4 2 1 3 8
-8 -7 -6 -5 -4 -3 -2 -1
Backword Indexing
CREATING A LIST
n=[7,5,9,4,2,1,3,8]
n=[ ]
n=list()
n=[7,5,9,4,2,1,3,8] OUTPUT
print(n[2]) 9
n=[7,5,9,4,2,1,3,8] OUTPUT
print(n[-2]) 3
n=[7,5,9,4,2,1,3,8] OUTPUT
print(n[2:6]) [9, 4, 2, 1]
n=[7,5,9,4,2,1,3,8] OUTPUT
print(n[0:7:2]) [7, 9, 2, 3]
n=[7,5,9,4,2,1,3,8] OUTPUT
print(n[2:]) [9, 4, 2, 1, 3, 8]
n=[7,5,9,4,2,1,3,8] OUTPUT
print(n[:5]) [7, 5, 9, 4, 2]
n=[7,5,9,4,2,1,3,8] OUTPUT
print(n[-5:-1]) [4, 2, 1, 3]
n=[7,5,9,4,2,1,3,8] OUTPUT
print(n[::-1]) [8, 3, 1, 2, 4, 9, 5, 7]
a=[2,4,6] OUTPUT
b=[3,8,9] [2, 4, 6, 3, 8, 9]
print(a+b)
a=[2,4,6] OUTPUT
print(a*2) [2, 4, 6, 2, 4, 6]
n.pop(2)
print(n)
n=[7,5,9,2,4]
n.reverse()
print(n)
del list[i] Removes element of list at particular index [7, 5, 2, 4, 1, 3]
n=[7,5,9,2,4,1,3]
del n[2]
print(n)
del list[n:m] Removes element of list in the range [7, 5, 1, 3]
n=[7,5,9,2,4,1,3]
del n[2:5]
print(n)
Write a function square (L) where L is list passed as argument to the function the
function returns another list m that stores squares of non zero elements
If L contains L=[9,4,0,11,0,6,0]
m will have [81, 16, 121, 36]
def square(L):
m=[]
for z in L:
if z!=0:
m.append(z*z)
return(m)
L=[9,4,0,11,0,6,0]
m=square(L)
print(m)