ProgrammingModerateTCS NQT · Infosys

What is printed?

What is printed?
print(list(zip('ab', [1, 2, 3])), dict(zip('ab', [1, 2, 3])))
  1. A. [('a', 1), ('b', 2), ('x', 3)] {'a': 1, 'b': 2}
  2. B. [('a', 1), ('b', 2)] {'a': 1, 'b': 3}
  3. C. [('a', 1), ('b', 2)] {'a': 1, 'b': 2}
  4. D. [('a', 1), ('b', 2)] {'a': 1, 'c': 2}

Correct answer: C. [('a', 1), ('b', 2)] {'a': 1, 'b': 2}

zip stops at the shorter iterable, so the 3 is dropped. dict(zip(...)) builds the same pairs, so the extra value is never used.

More Python Programming questions

Exams that ask this topic