Assignment on lists
Assignment on lists
1. Define List.
2. What do you mean by traversal of a List?
3. Explain the concept of slicing with the help of an example.
4. What is the difference between append() and extend() in list?
5. How do we convert a string value into a list?
6. Assuming that A is a list, differentiate between:
(i) A[2] and A[2:]
(ii) A[2:] and A[:2]
7. Consider the list list1=[”Computer Science”,”physics”,”chemistry”,”maths”,”English”] write
statements in python to implement the following:
a) To display last 3 elements of the list.
b) To display the part of list starting from index 1 to index 3(both inclusive).
c) To check if the list has alphanumeric values or not.
d) To display the index for the value “physics”.
e) To delete the last element of the list.
f) To replace the subject “English” with “Core English”
g) To display the number of elements in a list.
1
g) To print the diagonal values of a 3x3 matrix.
h) To replace all the even values present in the list of 10 numbers by add 5 to it.
9. Predict the output of the following codes:
a) L1 = list('4320187')
L1[0] = L1[5] = 0
L1[3] = L1[-2]
print(L1)
b) l1=[1,2,3]
print(l1*2)
c) a=[[[1,2],[3,4],5],[6,7]]
print(a[0][1][1])
d) a,b =[3,2,1],[5,4,6]
print(a+b)
e) a=[2,1,3,5,4]
a.remove(2)
print (a)
10.Convert and predict the output for the following code using list comprehension to a simple
python code:
a) pow2=[2**x for x in range(10) if x>5]
pow2
b) l=[x+y for x in [‘python’,’c’]for y in [‘language’,’programmoing’]]
print(l)