List Manipulation || Type B || Sumita Arora || Class 11 || Computer science || Information practices || Solution



Q1. What is the difference between following two expressions, if Ist is given as [1, 3, 5]
(i) lst * 3
(ii) lst *= 3





Q2. Given two lists

L1 = ["this", "is", 'a', "List"]
L2 = ["this", ["is", "another"], "List"]

Which of the following expressions will cause an error and why?

(a)
L1 == L2

(b)
L1.upper ( )

(c)
L1[3].upper()

(d)
L2.upper ()

(e)
L2[1].upper()

(f)
L2[1][1].upper()






Q3. From the previous question, give output of expressions that do not result in error.




Q4. Given a list L1 = [3, 4.5, 12, 25.7, [2, 1, 0, 5], 88]

(a) Which list slice will return [12, 25.7, [2, 1, 0, 5]
(b) Which expression will return [2, 1, 0, 5]
(c) Which list slice will return [2, 1, 0, 5]
(d) Which list slice will return [4.5, 25.7, 88]






Q5. Given a list L1 = [3, 4.5, 12, 25.7, [2, 1, 0, 5], 88] which function can change the list to:

(a) [3, 4.5, 12, 25.7, 88]
(b) [3, 4.5, 12, 25.7]
(c) [[2, 1, 0, 5], 88]






Q6. What will the following code result in?

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





Q7. Predict the output:

my_list = ['p', 'r', 'o', 'b', 'l', 'e', 'm']
my_list [2:3] = []
print (my_list)
my_list[2:5] = []
print (my_1ist)





Q8. 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)




Q9. Predict the output:

Odd = 1, 3, 5
print (Odd + [2, 4, 6])[4] )
print (Odd + (12, 14, 16] ) [4] - (Odd + [2, 4, 6] [4] )






Q10. Predict the output:

a, b, c = [1,2], [1, 2], [1, 2]
print (a ==b)
print (a is b)






Q11. Predict the output of following two parts. Are the outputs same? Are the outputs different? Why?

(a)
L1, L2 = [2, 4], [2, 4]
L3 = L2
L2[1] = 5
print(L3)

(b)
L1, L2 = [2, 4], [2, 4]
L3 = list(L2)
L2[1] = 5
print (L3)





Q12. Find the errors:

L1 = [1, 11, 21, 31]
L2 = L1 + 2
L3 = L1 * 2
Idx = L1.index(45)






Q13. Find the errors:

(a)
L1 = [ 1, 11, 21, 31]
An = L1.remove(41)

(b)
L1 = [ 1, 11, 21, 31]
An = L1.remove (31)
print (An + 2)







Q14. Find the errors:
   
(a)
L1 = [3, 4, 5]
L2 = L1 * 3
print (L1 * 3.0)
print (L2)

(b)
L1 = [3, 3, 8, 1, 3, 0, '1', '0', '2', 'e', 'w', 'e', 'r']
print (L1 [: : -1])
print (L1 [-1: -2: -3])
print (L1 [-1: -2: -3: -4])






Q15. What will be the output of following code?

x = ['3', '2', '5']
y = " "
while x :
    y = y + x [-1]
    x = x [: len(x) -1]
print (y)
print (x)
print (type(x), type(y))



Q16. Complete the code to create a list of every integer between 0 and 100, inclusive, named nums1 using Python, sorted in increasing order.




Q17. Let nums2 and nums3 be two non-empty lists. Write a Python command that will append the last element of nums3 to the end of nums2.




Q18. Consider the following code and predict the result of the following statements.

bieber = ['om', 'nom', 'nom']
counts = [1, 2, 3]
nums = counts
nums.append (4)

(i) counts is nums
(ii) counts is add([1, 2], [3, 4])





Q19. What is the output of the following code?

numbers = list( range(0, 51, 4))
results = []
for number in numbers:
    if not number % 3:
        results.append(number)
print(results)





Q20. Following code prints the given list in ascending order. Modify the code so that the elements are printed in the reverse order of the result produced by the given code.

numbers = list(range(0, 51, 4))
i = 0
while i < len(numbers):
    print(numbers[i], end = " ")
    i += 3
# gives output as : 12 24 36 48


6 Comments

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post