CBSE CS

cbse cs logo

Home

List in Python

 

 

Chapter List Syllabus 

 

 

Lists: introduction, indexing, list operations (concatenation, repetition, membership and
slicing), traversing a list using loops, built-in functions/methods–len(), list(), append(),
extend(), insert(), count(), index(), remove(), pop(), reverse(), sort(), sorted(), min(), max(),
sum(); nested lists, suggested programs: finding the maximum, minimum, mean of numeric
values stored in a list; linear search on list of numbers and counting the frequency of
elements in a list.

 
 

 

MCQs

 

1. The data type list is an ordered sequence which is and made up of one or more elements.
a. Mutable
b. Immutable
c. Both a) and b)
d. None of the above

2 Which statement from the list below will be create a new list?
a. new_l = [1, 2, 3, 4]
b. new_l = list()
c. Both a) and b)
d. None of the above

3 What will be the output of the following python code
new_list = [‘P’,’y’,’t’,’h’,’o’,’n’]
print(len(new_list))
a. 6          b. 7            c. 8               d. 9

4 Python allows us to replicate a list using repetition operator depicted by symbol .
a. –               b. +                  c. /                  d. *

5 We can access each element of the list or traverse a list using a .
a. for loop                                   b. while loop
c. Both a) and b)                       d. None of the above

6 a single element passed as an argument at the end of the list.
a. append()                                       b. extend()
c. insert()                                          d. None of the above

7 returns index of the first occurrence of the element in the list. If the element is not present, ValueError is generated.
a. insert()                                          b. index()
c. count()                                          d. None of the above

8 function returns the element whose index is passed as parameter to this function and also removes it from the list.
a. push()                                             b. remove()
c. pop()                                               d. None of the above

9 What will be the output of the following python code.
new_list = “1234”
print(list(new_list))
a. [‘1’, ‘2’, ‘3’, ‘4’]                                 b. (‘1’, ‘2’, ‘3’, ‘4’)
c. {‘1’, ‘2’, ‘3’, ‘4’}                                 d. None of the above

10 Suppose list1 is [4, 2, 2, 4, 5, 2, 1, 0], which of the following is correct syntax for slicing operation?
a) print(list1[0])                                  b) print(list1[:2])
c) print(list1[:-2])                               d) all of the mentioned

11 Suppose list1 is [2, 33, 222, 14, 25], What is list1[-1] ?
a) Error                                          b) None c) 25 d) 2

12 Suppose list1 is [1, 3, 2], What is list1 * 2 ?
a) [2, 6, 4]                                                  b) [1, 3, 2, 1, 3]
c) [1, 3, 2, 1, 3, 2]                                     d) [1, 3, 2, 3, 2, 1].

13 What is the output when following code is executed ?
>>>list1 = [11, 2, 23]
>>>list2 = [11, 2, 2]
>>>list1 < list2 is
a) True                           b) False                    c) Error                    d) None

14 To insert 5 to the third position in list1, we use which command ?
a) list1.insert(3, 5)                                  b) list1.insert(2, 5)
c) list1.add(3, 5)                                      d) list1.append(3, 5)

In the following questions(15 to 20) , a statement of assertion (A) is followed by a statement of reason(R) . Make the correct choice as :
(a) Both A and R are true and R is the correct explanation for A
(b) Both A and R are true and R is not the correct explanation for A
(c) A is True but R is False (or partially True)
(d) A is false( or partially True) but R is True

15 Assertion: In python, unlike other types, you can change elements of a list in place.
      Reason: Lists are mutable sequences.

16 Assertion: Any comma-separated group of values creates a list.
      Reason: Only a group of comma-separated values or expressions enclosed in [ ] , creates a list.

17 Assertion: Lists and strings have similar types of indexing.
Reason: Both lists and strings have two-way indexing , forward indexing and backward indexing.

18 Assertion :Lists are similar to strings in a number of ways like indexing , slicing and accessing individual elements.
      Reason : Lists, unlike strings , are mutable.

19 Assertion : The membership operators in and not in work in the same way on lists as they do , with strings.
Reason :Some operators work differently on strings and lists , such as + and * .

20 Assertion: A list slice is an extracted part of a list.
Reason: A list slice is a list in itself.

 

WORKSHEETS

 

CLASS: XI – List (LEVEL 1)

 

1. If L= [15, 25, 30, 5, 10, ‘python’, ‘program’] then what will be the output of L[5] and L[2].

2. Why are lists called mutable types? 

3. Write the name of the joining operator used for list data type.

4. Evaluate following expressions for given list:

a = [5, 4, 3, 10, 6]
i.  a[0]
ii.  a[-2]
iii.  a[2:5]

5. What will be the result of following expression:
L=[20, 3, 5, 11, 15]
a. len(L)
b. L + “abc”
c. L * 3

6. What is the difference between pop( ) and remove( ) method.

7. Which of the following operator is used for replicating a list?
        a. –              b. *                c. +              d. /

8. Which function will return the smallest element from a list?

9. Find out the errors and write the correct code :
a=[5, 6, 3, 4, 1]
b=a* ”3”
c=a+b

10. Write a program to find the largest and smallest number in a list.

 

 

CLASS: XI – List (LEVEL 2)

1. List can contain values of these types:
           a. integers                 b. float                         c. lists                d. all of these

2. Which of the following function is used to add an element at the end of the list.
          a. extend()                 b. append()               c. insert()            d. None of the above 

3. How to create a mixed data type list?

4. What will be the output of following code:
L=[3, 5, 1, 10, 2]
L.append(55)
print(L)

5. Write down the output after performing given function:
X = [5, 10, ‘python’, ‘XI’, 5.6]
a. X[X[0]]
b. X[-1 : -5]
c. X.insert(3, 99)

6. What is the use of the clear( ) function?

7. What will be the output of the following statements?
i)

list1 = [12,32,65,26,80,10]
list1.sort( )
print(list1)

ii) 

list1 = [12,32,65,26,80,10]
      sorted(list1)
     print(list1)

iii)

list1 = [1,2,3,4,5,6,7,8,9,10]
list1[::-2]
list1[:3] + list1[3:]

iv)

list1 = [1,2,3,4,5]
list1[len(list1)-1]

8. Find out the error in the given code and write the reason :
sub=[‘eng’, ‘cs’, ‘ip’, ‘maths’, ‘che’]
sub + ‘phy’

9.  Write the difference between sort( ) and sorted( ) functions.

10. Define slicing and explain with examples.

11. Write a program to input a list and an element, and remove all occurrences of the given element from the list.

 

CLASS: XI – List (LEVEL 3)

1. What will be the output of following code:
l=”Welcome to Python”.split()
print(l)

2. What will be the output of following code:
a=[[[1,2],[3,4],5],[6,7]]
print(a[0][1][1] )

3. What will be the output of following program:
a=[2,1,3,5,2,4]
a.remove(2)
print(a)

4. Differentiate between append( ) and extend() function.

5. Write a Python Program to Find the Second Largest Number in a List .

6. What will be the output of following program:
my_list = [‘p’, ‘r’, ‘o’, ‘b’, ‘l’, ‘e’, ‘m’]
print(‘p’ in my_list)
print(‘a’ in my_list)
print(‘c’ not in my_list)

7. What will be the output of the following program:
l=[6,12,18,24,30]
for i in l:
    for j in range(1,i%4):
          print(j,’#’,end=”)
    print( )

8. Write a Program to Print list having numbers less than 10.

9. What will be the output of the following program:

10.l=[10,20,30,40,50,60]
for i in range(len(l)):
      if(i%2==0):
             print(l[i],end=’#’)
      else:
            print(l[i],end=’@’)

11.Take a list of 10 elements. Split it into middle and store the elements in two different lists.
E.g.- INITIAL list : 5 10 6 12 3 25 66 44 1 90
After splitting : 5 10 6 12 3
25 66 44 1 90 

12.What will be the output of following program:
odd = [1, 9]
odd.insert(1,3)
print(odd)
odd[2:2] = [5, 7]
print(odd)

13.What will be the output of following program:
list(“a#b#c#d”.split(‘#’))

 

 

UNSOLVED QUESTIONS

 

Q1. WAP to find minimum element from a list of elements along with its index in the list.
Q2.WAP to Calculate mean of the given list of numbers.
Q3. WAP to search for an element in a given list of numbers.
Q4. WAP to count the frequency of a given element in the list of numbers.
Q5. Differentiate between append( ) and extend ( ) functions in Python.

 

 

51. Given the list L=[11,22,33,44,55], write the output of print(L[: :-1]).
i. [1,2,3,4,5]

ii. [22,33,44,55]

iii. [55,44,33,22,11]

iv. Error in code

 

52. Which of the following can add an element at any index in the list?
i. insert( )

ii. append( )

iii. extend()

iv. all of these

 

53 Which of the following function will return a list containing all the words of the given string?
i . split()

ii. index()

i i i . count()

iv. list()

 

54. Which of the following statements are True.
a. [1,2,3,4]>[4,5,6]
b. [1,2,3,4]<[1,5,2,3]
c. [1,2,3,4]>[1,2,0,3]
d. [1,2,3,4]<[1,2,3,2]
i. a,b,d

ii. a,c,d

iii. a,b,c

iv. Only d

 

55. If l1=[20,30] l2=[20,30] l3=[‘20’,’30’] l4=[20.0,30.0]

then which of the following statements will not return ‘False’:

a. >>>l1==l2

b. >>>l4>l1

c. >>>l1>l2

d. >>> l2==l2
i. b, c

ii. a,b,c

iii. a,c,d

iv. a,d

 

56. >>>l1=[10,20,30,40,50]
>>>l2=l1[1:4]
What will be the elements of list l2:
i. [10,30,50]

ii. [20,30,40,50]

iii. [10,20,30]

iv. [20,30,40]

 

57. >>>l=[‘red’,’blue’]
>>>l = l + ‘yellow’
What will be the elements of list l:
i. [‘red’,’blue’,’yellow’]

ii. [‘red’,’yellow’]

iii. [‘red’,’blue’,’yellow’]

iv. Error

 

58. What will be the output of the following code:
>>>l=[1,2,3,4]
>>>m=[5,6,7,8]
>>>n=m+l
>>>print(n)
i. [1,2,3,5,6,7,8]

ii. [1,2,3,4,5,6,7,8]

iii. [1,2,3,4][5,6,7,8]

iv. Error

 

59. What will be the output of the following code:
>>>l=[1,2,3,4]
>>>m=l*2
>>>n=m*2
>>>print(n)
i [1,2,3,4,1,2,3,4,1,2,3,4]

ii. [1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4]

iii. [1,2,3,4][4,5,6,7]
iv. [1,2,3,4]

 

60. Match the columns: if
>>>L=list(‘computer’)

1. L[1:4] a. [‘t’,’e’,’r’]
2. L[3:] b. [‘o’,’m’,’p’]
3. L[-3:] c. [‘c’,’o’,’m’,’p’,’u’,’t’]
4. L[:-2] d. [‘p’,’u’,’t’,’e’,’r’]

i. 1-b,2-d,3-a,4-c                                     iii. 1-c,2-b,3-a,4-d
ii. 1-b,2-d,3-c,4-a                                    iv. 1-d,2-a,3-c,4-b

 

61. If a list is created as
>>>l=[1,2,3,’a’,[‘apple’,’green’],5,6,7,[‘red’,’orange’]] 

then what will be the output of the following statements:
>>>l[4][1]
i. ‘apple’                                         iii. ‘green’
ii. ‘red’                                            iv. ‘orange’

 

62. >>>l[8][0][2]
i. ‘d’                                                 iii. ‘e’
ii. ‘r’                                                 iv. ‘o’

 

63. >>>l[-1]
i. [‘apple’,’green’]                                               iii. [‘red’,’orange’]
ii. [‘red’ ]                                                              iv. [’orange’] 

 

64 >>>len(l)

i. 10                                               iii. 9
ii. 8                                               iv 11

 

65. What will be the output of the following code:
>>>l1=[1,2,3]
>>>l1.append([5,6])
>>>l1
i. [1,2,3,5,6]                                            

  ii. [1,2,3,[5,6]]                                            

  iii. [[5,6]]                                              

 iv. [1,2,3,[5,6]]

 

66. What will be the output of the following code:
>>>l1=[1,2,3]
>>>l2=[5,6]
>>>l1.extend(l2)
>>>l1
i. [5,6,1,2,3] 

ii. [1,2,3,5,6]

iii. [1,3,5]

iv. [1,2,3,6]

 

67. What will be the output of the following code:
>>>l1=[1,2,3]
>>>l1.insert(2,25)
>>>l1
i. [1,2,3,25]

ii. [1,25,2,3]

iii. [1,2,25,3]

iv. [25,1,2,3,6]

 

68. >>>l1=[10,20,30,40,50,60,10,20,10]
>>>l1.count(‘10’)
i. 3               

ii. 0                                              

iii. 2                                              

iv. 9

 

69. Which operators can be used with list?
i. in

ii. not in

iii. both (i)&(ii)

iv. Arithmetic operator only

 

70. Which of the following function will return the first occurrence of the specified element in a list.
i. sort()

ii. value()

iii. index()

iv. sorted()

 

error: Content is protected !!