You are on page 1of 4

CLASS 11: COMPUTER SCIENCE

WORKSHEET ON LIST(2022-23)
1. Predict the output –

List1= [13, 18, 11, 16, 13, 18, 13]


print (List1.index (18))
print (List1.count (18))
List1.append (List1.count (13))
print(List1)
2. Predict the output –

L1= [1,3,5,7,9]
print(L1==L1.reverse())
print (L1)

3. Find the output of the following code

sampleList = [10, 20, 30, 40, 50]


print(sampleList.pop())

4. Is a list mutable?
a) Yes
b) No
5. What is the output of the following code:
b = [1,2,3]
b.extend([5,6])
print(b)
6. What is the output when we execute list(“hello”)?

7. aList = ["PYnative", [4, 8, 12, 16]]


print(aList[0][1],aList[1][3])
a. P 8
b. Y 16
c. Y 8
8. Start with the list[8,9,10]. Do the following using list functions
(a) Set the second entry (index 1) to 17
(b) Add 4, 5 and 6 to the end of the list as individual element
(c) Remove the first entry from the list.
(d) Sort the list.
(e) Double the list.
(f) Insert 25 at index 3

9 . Let L1=[21,14,21,[24,25],21,”Welcome”]
i. Write a statement to print 24
ii. What will be the output of the following statements?
a. print(L1[-1][-1])
b. L1.insert(len(L1), "sam",)
print(L1)
10. Find the output of the following code

s=["There",["are","a"],["few","words"],"that","we","will","use"]
print(len(s))
print(s[3:4]+s[1:2])
print(s[2][1:])

11. Find the output of the following code

s1=["There","are","a",["few","words"],"that","we","will","use"]
print(s1[3:4])
print(s1[3:4][0])
print(s1[3:4][0][1])

12. Consider the following code, and identify the datatype of L in Line 4
13. Which of the following removes the middle element 3 from the list A=[1,2,3,4,5]?
i) del A[3] iii) A[2]=[ ]
ii) A.remove(3) iv) A[2:2]=[ ]
14. Write a command to add 25 at the 3rd index position in to a list Mylist=[20,22,24,26,28].
i) Mylist.extend (25) iii) Mylist.append(25)
ii) Mylist.insert(25,3) iv) Mylist.insert(3,25)
15. Predict the output for the following code snippet:
lst=["AISSCE",[2020,2021,2022],["Elective","083"]]
for i in range(len(lst)):
print(len(lst[i]))
else:
lst.extend([23,44])
print(len(lst))
16. Predict the output for the following code snippet:
L1= [100,900,300,400,500]
START = 1
SUM = 0
for C in range(START,3):
SUM = SUM + L1[C]
print(C, “:",SUM)
SUM = SUM + L1[0]*10
print(SUM)
17. What will be the output of the following python statement ?
L=[1,2,3,4,5,6]
L=L+[50]
print(L)
18. Write the output of the following
TXT=["20","50","30","40"]
CNT=3
TOTAL=0
for C in [7,5,4,6]:
T=TXT[CNT]
TOTAL=float (T)+C
print(TOTAL)
CNT=CNT-1
19. Predict the output
list=['p','r','o','b','l','e','m']
print(list[1:3])
list[1:3]=[]
print(list)
list[2:5]=[]
print(list)
20. Predict the output
str='''Twinkle, twinkle, little star How I wonder what you are
Up above the world so high Like a diamond in the sky
Twinkle, twinkle, little star'''
str=str.split('\n')
count=0
for i in str:
if i[0].lower()=='t':
count+=1
print(count)
21. What shall be the output for execution of the code given below?
REC = [ 'UNIQUE' , 'DEFAULT' ]
REC[1], REC[0]=REC[0],REC[1]
print(REC)
22. What is the output of the following?
x = ['ab', 'cd']
for i in x:
x.append(i.upper())
print(x)

(a) [‘AB’, ‘CD’]


(b) [‘ab’, ‘cd’, ‘AB’, ‘CD’]
(c) [‘ab’, ‘cd’]
(d) none of the mentioned

You might also like