List Worksheet
List Worksheet
G B PUBLIC SCHOOL
DEPARTMENT OF COMPUTER SCIENCE
CLASS XI LIST WORKSHEET
Q1. Identify the output of the following Python statements.
L1=[6,4,2,9,7]
L1[3:]= “100”
(a) [6,4,2,9,7,100] (b) [6,4,2,100] (c) [6,4,2,1,0,0] (d) [6,4,2, ‘1’,’0’,’0’]
Q2. What will be the output of following Python Code:
data=[10,"ram",20,"sham",30,"anil"]
data.append("Sunil")
data[2]="Raj"
data.pop()
del data[1]
data[-1]="Magic"
print(data)
Q3. What will be the output of following Python Code:
numbers=[10,15,20,25]
for i in range(len(num)):
if num[i]%2==0:
num[i]/=2
else:
num[i]*=2
Q4. What will be the output of following Python Code:
data=[10,20,30,40,50,60]
for x in range(0,len(num),2):
num[x], num[x+1]=num[x+1], num[x]
Q5. Identify the output of the following Python statements:
L= [3,1,4]
M= [11, 5, 9]
L.insert(1,21)
M.insert(0,7)
l = len(L)
N= [ ]
for a in range (l) :
N.append(L[a]+M[a])
print(N)
Q6. L = [12, 25, 8, 75]
for i in range (N):
if M[i]%5 == 0:
M[i] //= 5
if M[i] %3 == 0:
M[i] //= 3
for i in L:
print(i, end = "#")
Q7. Identify the output of the following Python statements.
l1 = [10,15,16,18,20]
l1.remove(15)
l1.insert(1,30)
print (l1[::-2])
Q8. Identify the output of the following Python statements.
lst = [40, 15, 20, 25, 30]
lst.sort()
lst.insert(3, 4)
lst.append(23)
print(lst)
Q9. Write the output of the following code:
L = [30,5,13]
for i in range(N):
if M[i]%2 == 0:
M[i]//=2
if M[i]%5 == 0:
M[i]//=5
for i in L:
print(i,end=" @ ")
Q10. Write the output of the following:
print(list(i*2 for i in range(4)))
print(list(range(4)))
Q11. What will be the output of the following Python code : (5)
mylist =[‘java’,’c++’,’python’,’vb’,’vc++’,’php’,’cobol’]
print(mylist.pop())
mylist.append(‘c#’)
print(len(mylist))
mylist.insert(3,’basic’)
print(mylist)
mylist.sort()
print(mylist)
mylist.index(‘php’)
Q12. Predict the output of the following code:
S='AIM'
L=[10,21,33,4]
for i in range(len(S)):
if i%2==0:
L.insert(i,S[i])
else:
L.pop(i)
print(L)
else:
print(L.clear(),len(L))
Q13. Given Lst=[30,10,90,80], which of the following will remove all the elements in the
list and make it an empty list:
a. del Lst[:] b. Lst[:] = [] c. del Lst[0:len(Lst)] d. All of the above
Q14. Write the Python statement(Single statement only) for each of the following tasks
using BUILT-IN functions/methods only:
(i) To return the list L sorted in descending order
(ii) To search a substring SS in the main string MS and return
the index of the substring SS if found otherwise an error.
(iii) To add the elements of list L2 in L1
(iv) To check whether a string named, sample ends with a full stop/period or not
Q15. Consider:
Str,Lst=”Global warming”,[‘E’,’X’,’A’,’M’,’2023’]
Write Python statement(single statement only) for each of the
following tasks using BUILT-IN functions/methods only:
(i) To replace all occurrences of letter ‘a’ in the string with ‘*’
(ii) To return the highest and the least value in the list
(iii) To check if the string is in title case
(iv) To arrange the list elements in alphabetical order.
Q16. Give the output of the following code::
L=[10,31,11,34,23,46]
for i in range(len(L)):
if L[i]%2!=0 and i%2==0:
L[i]+=10
elif L[i]%2==0:
L[i]*=3
else:
L[i]=0
print(L)