ProgrammingModerateTCS CodeVita · Infosys HackWithInfy

What is printed?

What is printed?
seen = {}
for i, x in enumerate([2, 7, 11, 15]):
    if 9 - x in seen:
        print((seen[9 - x], i))
        break
    seen[x] = i
  1. A. (1, 2)
  2. B. (0, 2)
  3. C. (2, 3)
  4. D. (0, 1)

Correct answer: D. (0, 1)

For x = 7 the complement 9 - 7 = 2 is already in seen at index 0, so the pair is (0, 1).

More Python Programming questions

Exams that ask this topic