CBSE Class 12 Computer Science
Question 23 of 68
Data Structures - I : Linear Lists — Question 5
Back to all questions 5
Question Which of the following is the correct expansion of list_1 = [expr(i) for i in list_0 if func(i)] ?
(a)
list_1 = []
for i in list_0:
if func(i):
list_1.append(i)
(b)
for i in list_0:
if func(i):
list_1.append(expr(i))
(c)
list_1 = []
for i in list_0:
if func(i):
list_1.append(expr(i))
(d) none of these
list_1 = []
for i in list_0:
if func(i):
list_1.append(expr(i))
Reason —
for i in list_0— This part iterates over each elementiin the listlist_0.if func(i)— This part applies the functionfunc()to each elementiand checks if the result is True. Only elements for whichfunc(i)returns True will be included in the resulting list.expr(i)— This part applies some expression or function callexpr()to each selected elementi.
Therefore, the correct expansion would be:
list_1 = []
for i in list_0:
if func(i):
list_1.append(expr(i))