ProgrammingHardHCL · Tech Mahindra · Python placement

What does the following Python 3 code print? print(dict(enumerate(["x", "y", "z"])))

  1. A. {0: 'x', 1: 'y', 2: 'z'}
  2. B. {1: 'x', 2: 'y', 3: 'z'}
  3. C. {'x': 0, 'y': 1, 'z': 2}
  4. D. {0: 'x', 1: 'y'}

Correct answer: A. {0: 'x', 1: 'y', 2: 'z'}

enumerate pairs each element with its 0-based index; dict() turns those (index, value) pairs into key:value entries.

More Python Programming questions

Exams that ask this topic