List Manipulation in Python Questions and Answers

List Manipulation in Python Questions and Answers, Assignment solutions for CBSE Class 11. This post contains the solutions of List Manipulation Chapter of Sumita Arora Computer Science (Python) book. Conceptual, application and coding question and answer are very useful for annual exam.

Short Questions : List Manipulation in Python

Q.1. Discuss the utility and significance of lists, briefly.

Answer: Lists are the array of Python. Its significance is this that they can be used as data containers and store many type of Data. They are mutable.

Q.2. What do you understand by mutability? What does “in place” memory updation mean?

Answer: Mutability we can change the data stored in list. Example:- list, sets, dictionary
“In place” memory updation mean that we can change elements of list in the same memory cell can be changed.

Q.3. 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
(c) Remove the first entry from the list
(d) Sort the list
(e) Double the list
(f) Insert 25 at index 3

Answer =
(a)l. insert(2,17)
(b) l. append(4,5,6)
(c) l. pop(0)
(d) l. sort()
(e) l. extend(l)
(f) l. insert(3, 25)

Q4. If a is [1, 2, 3]
(a)what is the difference (if any) between a * 3 and [a, a, a]?
(b) is a * 3 equivalent to a + a + a?
(c) what is the meaning of a[1 : 1 ] = 9?
(d) what’s the difference between a[1:2] 4 and a[1:1]

Answer =
a =a * 3 [a, a, a]
b =Yes
c =
a[1:1] = 9
first of all it give error.
d =
a[1:2 ] = 4 will give error because they are non sequence value.

Q.5. What’s a[1 : 1] if a is a string of at least two characters? And what if string is shorter?

Answer =
a[1:1] blank list will be printed.

Q.6. What’s the purpose of the del operator and pop method? Try deleting a slice.

Answer : del operator and pop method both are being used to delete the values from the list.
del is been used to delete the value by slice while pop is being used to delete value by the particular index number and also it will return the deleted value.

myList = ["Bran",11,22,33,"Stark",22,33,11] 
del myList[1:4]
myList

OUTPUT:  [‘Bran’, 22, 33, 11]

Q.7.What does each of the following expressions evaluate to? Suppose that L is the list
[“These”, [“are”, “a”, “few”, “words”], “that”, “we”, “will”, “use”].

(a) L[1][0::2]
(b) “a” in L[1] [0]
(c) L[:1] + L[1]
(d) L[2: :2]
(e) L[2][2] in L[1]

Answer =
(a) [“are”, ” few”]
(b) True
(c) [“There “, “are “, “a “, “few “, “word”]
(d) [“that “, “will”]
(e) True

Q.8. What are list slices? What for can you use them?

Answer =
list slices are used make another slices from a list which is itself a list . So when we require a particular record from somewhere to somewhere else then it is used.

Q.9. Does the slice operator always produce a new list?

Answer =
yes, it will give the copy part of list which is asked for.

Q.10. Compare lists with strings. How are they similar and how are they different?

Answer :
similarity is that they both stores the values.
Different they are in the sense that list are mutable but string are inmutable.

Q.11. What do you understand by true copy of a list? How is it different from shallow copy? 

Answer: A shallow copy constructs a new compound object and then (to the extent possible) inserts references into it to the objects found in the original. A deep copy constructs a new compound object and then, recursively, inserts copies into it of the objects found in the original.

Q.12.An index out of bounds given with a list name causes error, but not with list slices. Why?

Answer:
Slices are treated as boundaries instead, and the result will simply contain all items between the boundaries. For the start and stop given beyond list limits in a list slice (i.e., out of bounds), Python simply returns the elements that fall between specified boundaries, if any, without raising any error.

Application based Questions -List Manipulation in Python Class 11 Solutions

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

Answer =
lst*3 cannot be changed .
lst*=3 lst will change

Q.2. 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()

Answer :
cause an error:-
(b) (d) & (e) these functions applied in them are for strings not for lists.

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

Answer =
Output:
(a)
>>> L1 == L2
False
>>>
(c)
>>> L1[3].upper()
‘LIST’
>>>
(f)
>>> L2[1][1].upper()
‘ANOTHER’

Q.4. 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]

Answer:
(a)
>>> L1[ 2 : 5]
(b)
>>> L1[4]
(c)
>>> L1[4][:]
(d)
>> L1[1: :2]

Q.5. 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]

Answer:
(a)
>>> L1.pop (4)
Or
>>> del L1 [4]
(b)
>>> del L1 [4:]
(c)
>>> del L1[0:4]

Q.6. What will the following code result in?
L1 = [1, 3, 5, 7, 9]
print (L1 == L1.reverse())
print (L1)

Answer :
False
[9, 7, 5, 3, 1]

Q.7. 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_list)

Answer :
[‘p’, ‘r’, ‘b’, ‘l’, ‘e’, ‘m’]
[‘p’, ‘r’, ‘m’]

Q.8. 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)

Answer :
1
2
[13, 18, 11, 16, 13, 18, 13, 3]
>>>

Q.9.Predict the output:
Odd = 1, 3, 5
print (Odd + [2, 4, 6])[4])
print (Odd + (12, 14, 16] ) [4] – (Odd + [2, 4, 6] [4])

Answer :
It will give an error.

Q.10. Predict the output:
a, b, c = [1,2], [1, 2], [1, 2]
print (a == b)
print (a is b)

Answer :
True
False
>>>

Q.11. 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)

Answer:
(a)
41 is not present in list.
(b)
Line 3 .

Q.14. 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])

class 11 solutions

Type C : Programming Practice/ Knowledge based Questions-List Manipulation in Python Class 11 Solutions

Q.1. Write a program that reverses a list of integers (in place).
Answer:

i=0
lst = eval(input("Enter a list :-"))
lst.reverse()
print(lst)
#print(i)

Q.2.Write a program that input two lists and create a third, that contains all elements of the first followed by all elements of the second.
Answer:

i=0
a  = eval(input ("Enter the first list ="))
b = eval (input ("Enter the second list ="))
print ("new list = ", a+b)
#print(i)

Q.3.Ask the user to enter a list containing numbers between 1 and 12 then replace all of the entries in the list that are greater than 10 with 10.

Answer:
i=0
a  = eval(input ("Enter the list ="))
for i in range(len(a)) :
    if a[i] > 10 :
        a[i] = 10
print ("new list ",a)

#OR 
# By List Comprehension Method
#print(i)
a  = eval(input ("Enter the list ="))
newlist = [ x if x <= 10 else 10 for x in a ]
print(newlist)
#print(i)

 Q.4.Ask the user to enter a list of string. Create a new list that consist of those strings with their first characters removed.

Answer:
lst  = eval(input ("Enter the  list of string = "))
i=0
for i in range(len(lst)) :
    lst [ i ] = lst [ i ] [ 1:]
print("new list = ",lst)
#print(i)

Q.5. Create the following lists using a for loop:
a. A list consisting of the integers 0 through 49.
b. A list consisting the square of the integer 1 through 50

c. The list [“a”, “bb”, “ccc”, “dddd” ….] that ends with 26 copies of the letter z.

Answer:
#(a)
i=0
lst = [ ]
for i in range(50):
    lst = lst + [ i ]
print(lst)
#print(i)
#(b):
i=0
lst = [ ]
for i in range(51):
    lst = lst + [ i**2 ]
print(lst)
#print(i)

#(c):
i=0
lst = [ ]
for i in range(1,27):
    lst = lst + [ chr(96+i) * i ]
print(lst)
#print(i)

Q.6.Write a program that takes any two list l and m of the same size and adds their elements together to form a new list n whose element are sum of the corresponding elements in l and m.

Answer:
lst1 = eval(input("enter first  list = "))
lst2 = eval(input("enter second list = "))
lst3 = [ ]
i=0
for i in range(len(lst1)):
    lst3 = lst3 + [ lst1 [ i ] + lst2 [ i ] ]
print("new list = ",lst3)
#print(i)

Q.7.Write a program rotates the elements of a list show that the element at the first index moves to the second index, the element i n second index moves to the third index, etc, and the element in the last index moves to the first index.

Answer:
i=0
lst = eval(input("enter the list = "))
print ("New list =", [lst[ -1] ] + lst[0 : -1] )
#print(i)

Q.8.Write a program that reads the n to display 9 term of Fibonacci series:
The Fibonacci sequence work as follows :
0, 1, 1, 2, 3, 5, 8, 13, 21, 34, ……

Answer :
i=0
term = int (input ("Enter the number ="))
fib = [0,1,1]
for i in range(term - 2):
    fib = fib + [ fib [ i + 1] + fib [ i + 2 ] ]
print( fib [ term ] )
#print(i)

Q.9. Write a program as per following specifications:
(a)
”’print the length of the longest
String in the list of a strings str_list.
Precondition: the list will contain
At least one element .”’
(b)”’L is a list of numbers. return a new list where each element is the corresponding element of list L summed with number num.”’
Answer:  

Answer:
(a)
i=0
lst = eval(input("enter a list of string = "))
if lst == [] :
    print("list will contain at least one element ")
else :#print(i)
    long = ""
    for i in range(len(lst)) :
        if len(long ) < len(lst[i]) :
            long = lst[i]
    print("longest string in list = ",long)
#print(i)

#(b)

lst = eval(input("enter a list = "))
num = int(input("enter a number = "))
for i in range(len(lst)):
    lst[i] = lst[i] + num
print("new list = ",lst)

Thanks for reading the List Manipulation Class 11 in Python Assignment Solutions. Solved assignment of computer science python CBSE syllabus is provided on this site. Go through them to have a good score in exam. Also, Python practical exams question and solutions are provided here.

For solved assignments- Click here

For practical file question – Click here

Leave a Comment

Your email address will not be published.