CBSE Class 12 Computer Science
Question 48 of 68
Data Structures - I : Linear Lists — Question 4
Back to all questionsML = [1, 4, 9, 16, 25, 36, 49, 64, 81, 100]
A = [i for i in ML if i % 2 == 0]
print(A)[4, 16, 36, 64, 100]
ML = [1, 4, 9, 16, 25, 36, 49, 64, 81, 100]— This line initializes a listML.A = [i for i in ML if i % 2 == 0]— This line uses a list comprehension to create a new listA. It iterates over each elementiin the listML, and only includesiinAif i % 2 == 0 is true. This condition checks if the elementiis even.print(A)— This line prints the list A, which contains only the even numbers from the listML.