Worksheet List
Worksheet List
1. What is the difference between c[:] and c[:-1] assuming c is a list? [1]
2. Find the output of the following [2]
S=[10, “few”,38, “PAIN”,56, “ find”]
for i in range(len(S)):
if type(S[i])==int:
S[i]=S[i]**2
elif type(S[i])==str:
S[i]=(S[i]).swapcase()
print(S)
3. Write the output of the following: [2]
a) list1=[2,3,4,7,53,23,12,9,0]
L=list1.pop(9)
print(L)
print(list1[-4])
print(list1[5:])
b) Write a python statement which will be used to add a new element 14 to a list list1.
4. Find the output of the given questions. [1 ½ ]
L1=[1,2,3,4]
L2=[5,6,7,8]
print(len(L1*2))
print(L1+L2)
print(L1[4])
5. Write a program to calculate the average of the elements which are entered by the user. [2]
#input 5 numbers.
6. Write a program to count the even and odd numbers from the given list and [2]
display the sum of the list. S=[12,43,67,54,90,65,76]
The output should be:
Odd numbers: 3
Even numbers: 4
Sum of List: 407
7. Differentiate between del, remove( ), pop( ) and clear( ). [2]
8. Which of the following is true regarding lists in python? [½]
a) Lists are immutable.
b) Size of the lists must be specified before its initialization.
c) Elements of lists are stored in contiguous memory locations.
9. What will be the output of the following program [2]
L=[10,20,30,40,50,60,70]
x=int(len(L)/2)
for i in range(x):
L[i], L[x+i]=L[x+i], L[i]
print(L)