Exit Chapter 10 ยท ๐Ÿ“‹ List Manipulation โ€” Quiz

Playing as a guest? to earn XP and track your progress.

Question 1 of 58 0 correct so far

๐Ÿ“‹ List Manipulation Quiz

Q1.

Which statement best describes a Python list?

Explanation

A list is an ordered, mutable collection of values (elements) in square brackets, separated by commas.

Q2.

Which of these is a valid list containing values of different types?

Explanation

Lists are heterogeneous โ€” one list can hold int, str, float and bool values together.

Q3.

What is list("HELLO")?

Explanation

list() converts a sequence into a list of its items; a string gives its characters, and duplicates are kept.

Q4.

Which statement lets the user type a whole list such as [10, 20, 30] at once?

Explanation

eval(input()) evaluates the typed text [10, 20, 30] as a list.

Q5.

For L = [10, 20, 30, 40, 50], what does print(L[0], L[3], L[-1], L[-2]) display?

Explanation

L[0] = 10, L[3] = 40, L[-1] = 50 and L[-2] = 40.

Q6.

For L = [10, 20, 30, 40, 50], what does L[5] give?

Explanation

Valid indices are 0 to 4, so L[5] is out of range.

Q7.

What is L after this code?

L = [10, 20, 30, 40, 50] L[1] = 200 L[-1] = 500

Explanation

Lists are mutable, so their elements can be changed in place.

Q8.

Which statement comparing strings and lists is correct?

Explanation

L[0] = 99 works on a list, but s[0] = 'X' gives a TypeError on a string. Indexing and slicing rules are the same for both.

Q9.

What is the output of print([1, 2] * 2)?

Explanation
  • repeats the list.
Q10.

What does [1, 2] + 3 give?

Explanation

Both operands of + must be lists; write [1, 2] + [3].

Q11.

For colours = ["red", "green", "blue"], what is "Green" in colours?

Explanation

Membership testing is case-sensitive; "Green" is not the same as "green".

Q12.

What is the output of print([1, 2, 5] > [1, 2, 3])?

Explanation

Lists are compared element by element; at index 2, 5 > 3.

Q13.

What is the output of print([3] > [1, 9, 9])?

Explanation

The first elements already differ (3 > 1), which decides the comparison.

Q14.

For L = [11, 22, 33, 44, 55, 66, 77], what is L[1:4]?

Explanation

Indices 1, 2 and 3 are included; 4 is excluded.

Q15.

For L = [11, 22, 33, 44, 55, 66, 77], what is L[5:1:-2]?

Explanation

Going backwards from index 5 in steps of 2: indices 5 and 3 (1 is excluded).

Q16.

For L = [15, 25, 35, 45, 55, 65], what is L[-4:-1]?

Explanation

Index -4 is 35 and -1 (65) is excluded, giving 35, 45, 55.

Q17.

For L = [15, 25, 35, 45, 55, 65], what is L[::-2]?

Explanation

Start from the end and take every 2nd element going backwards.

Q18.

For L = [15, 25, 35, 45, 55, 65], what is L[10:]?

Explanation

Slicing beyond the end never raises an error; it returns an empty list.

Q19.

What is L after this code?

L = [1, 2, 3, 4, 5] L[1:3] = [20, 30, 35]

Explanation

The slice (indices 1-2) is replaced by three values, so the list grows.

Q20.

What does this loop do to the list?

marks = [85, 92, 78] for m in marks: m = m + 5

Explanation

To change the elements, loop over the indices and assign to marks[i].

Q21.

What is marks after this code?

marks = [85, 92, 78] for i in range(len(marks)): marks[i] = marks[i] + 5

Explanation

Assigning to marks[i] changes each element in place.

Q22.

What is printed after this code?

A = [1, 2, 3] B = A B[0] = 100 print(A)

Explanation

B = A creates an alias โ€” both names refer to the same list, so A also changes.

Q23.

Which of these does NOT create an independent copy of list A?

Explanation

B = A only creates an alias; A.copy(), list(A) and A[:] create real copies.

Q24.

What does this code print?

A = [1, 2, 3, 4] B = A C = A[:] B[0] = 100 C[1] = 200 print(A)

Explanation

B is an alias of A, so A shows the change to index 0; C is a separate copy, so its change does not affect A.

Q25.

For L = [4, 9, 1, 7], what are max(L), min(L) and sum(L)?

Explanation

The largest element is 9, the smallest is 1, and the sum is 4 + 9 + 1 + 7 = 21.

Q26.

For names = ["Riya", "Aman", "Zoya"], what is max(names)?

Explanation

Strings are compared alphabetically, and 'Zoya' is the largest.

Q27.

What happens with sum(["Riya", "Aman"])?

Explanation

sum() works on numbers only.

Q28.

What is L after this code?

L = [1, 2, 3] L.append([4, 5])

Explanation

append() adds its argument as ONE element, so the length becomes 4.

Q29.

What is L after this code?

L = [1, 2, 3] L.extend([4, 5])

Explanation

extend() adds each element of the sequence separately.

Q30.

For L = [], what is the difference between L.append("hi") and L.extend("hi")?

Explanation

extend() adds each item of a sequence, and a string's items are its characters.

Q31.

What is L after this code?

L = [1, 2, 3] L.insert(1, 10)

Explanation

insert(i, x) puts x at index i and shifts the rest right.

Q32.

What is printed after this code?

L = [1, 2, 3] L.insert(10, 4) L.insert(-1, 5) print(L)

Explanation

An index beyond the end adds at the end, giving [1, 2, 3, 4]; insert(-1, 5) then inserts before the last element.

Q33.

What is L after running L = L.append(5)?

Explanation

append() changes the list in place and returns None, so L becomes None. Just write L.append(5).

Q34.

For L = [10, 20, 30, 20], what do x = L.pop() and L become?

Explanation

pop() with no index removes and returns the last element.

Q35.

For L = [10, 20, 30, 20], what is L after L.remove(20)?

Explanation

remove() deletes only the FIRST occurrence of the value.

Q36.

For L = [5, 8, 3], what does L.remove(9) give?

Explanation

remove() raises a ValueError when the value is not in the list.

Q37.

For L = [5, 8, 3], what does L.pop(7) give?

Explanation

pop() with an invalid index raises an IndexError.

Q38.

Which statement comparing pop() and remove() is correct?

Explanation

pop(i) works by index and returns the element; remove(x) works by value and returns None.

Q39.

For L = [10, 20, 30, 20], what is L after del L[1:3]?

Explanation

del L[1:3] deletes indices 1 and 2 (20 and 30).

Q40.

What does L.clear() do?

Explanation

clear() empties the list, while del L deletes the variable itself.

Q41.

For L = [3, 7, 3, 9, 3], what are L.index(9) and L.count(3)?

Explanation

9 is first found at index 3, and 3 occurs three times.

Q42.

What happens when you call L.find(5) on a list?

Explanation

find() belongs to strings only; use L.index(x) for lists.

Q43.

For L = [4, 1, 3], what is L after L.reverse()?

Explanation

reverse() only flips the current order; it does not sort.

Q44.

How do you sort list L in descending order, in place?

Explanation

L.sort(reverse=True) sorts in descending order in place.

Q45.

What is printed after this code?

L = [40, 10, 30, 20] M = sorted(L) print(L)

Explanation

sorted() returns a NEW sorted list and leaves L unchanged.

Q46.

Which statement comparing sort() and sorted() is correct?

Explanation

sort() is a list method that works in place; sorted() is a built-in function that works on any sequence.

Q47.

What is words after this code?

words = ["banana", "Apple", "cherry"] words.sort()

Explanation

'A' (65) comes before lowercase letters such as 'b' (98).

Q48.

For M = [[1, 2, 3], [4, 5, 6], [7, 8, 9]], what is M[1][2]?

Explanation

Row 1 is [4, 5, 6], and column 2 of that row is 6.

Q49.

For M = [[1, 2, 3], [4, 5, 6], [7, 8, 9]], what is len(M)?

Explanation

len(M) counts the rows (the inner lists), so it is 3.

Q50.

What does len([1, [2, 3], 4]) return?

Explanation

The nested list [2, 3] counts as ONE element.

Q51.

What does the max/min/mean program print as the mean for L = [45, 12, 78, 34, 89, 23] (rounded to 2 decimal places)?

Explanation

The total is 281 and 281 / 6 = 46.833โ€ฆ, which rounds to 46.83.

Q52.

In the max/min program, why are largest and smallest set to L[0] at the start?

Explanation

Initialising both with the first element gives a valid starting point for the comparisons.

Q53.

How does linear search work?

Explanation

Linear search checks elements one by one; it works on unsorted lists, and in the worst case it checks all n elements.

Q54.

In the linear-search program for L = [34, 7, 23, 32, 5, 62], what is printed for the key 32?

Explanation

32 is at index 3 (34 is at 0, 7 at 1, 23 at 2).

Q55.

In the linear-search program, when does the for loop's else part print 'not found'?

Explanation

break runs only when the key is found; if it never runs, the loop's else executes.

Q56.

What does this remove-duplicates program print for L = [3, 1, 3, 2, 1, 4]?

for x in L: if x not in unique: unique.append(x)

Explanation

Each value is added the first time it appears, so the order is kept.

Q57.

What is L after this code?

L = [1, 2, 3, 4, 5, 6] mid = len(L) // 2 L = L[mid:] + L[:mid]

Explanation

mid = 3; the second half [4, 5, 6] is placed before the first half [1, 2, 3].

Q58.

What is printed after this code?

L = [3, 8, 1, 6, 8, 2] L.remove(8) x = L.pop(1) L.insert(2, x * 2) print(L)

Explanation

remove(8) gives [3, 1, 6, 8, 2]; pop(1) removes 1, giving [3, 6, 8, 2]; insert(2, 2) gives [3, 6, 2, 8, 2].