CBSE Class 12 Computer Science
Question 54 of 68
Data Structures - I : Linear Lists — Question 10
Back to all questions[0, 9, 36, 81, 4]
[0, 9, 36, 81, 4]
[0, 9, 36, 81]
L1 = [x ** 2 for x in range(10) if x % 3 == 0]— This line creates a listL1containing the squares of multiples of 3 between 0 to 9.L2 = L1— This line assigns listL1to listL2, meaning bothL1andL2reference the same list in memory (shallow copy).L1.append(len(L1))— This line appends the length ofL1toL1. So, the length ofL1is 4, and it appends 4 toL1.print(L1)— This prints the modifiedL1list.print(L2)— This printsL2, which is pointing to the same list asL1.L2.remove(len(L2) - 1)— This line removes the last element ofL2sincelen(L2) - 1gives the last index ofL2.print(L1)— This printsL1again. Since bothL1andL2reference the same list, modifyingL2also affectsL1. Therefore,L1also reflects the change made toL2.