ProgrammingVery hardGATE CS · Product-company placement

How many of these statements about CPython are correct? 1. A tuple is hashable only if all its elements are hashable. 2. `x in some_set` is O(1) on average, while `x in some_list` is O(n). 3. A generator expression computes all its values when it is created. 4. `copy.copy` of a list of lists shares the inner lists with the original.

  1. A. 3
  2. B. 2
  3. C. 4
  4. D. 1

Correct answer: A. 3

1, 2 and 4 are correct: hash(tuple) hashes each element, set lookup is a hash probe, and a shallow copy copies only the outer references. 3 is false: a generator expression is lazy and evaluates only its first iterable up front.

More Python Programming questions

Exams that ask this topic