Python · Question 23 · Medium

What will be the output of the following Python code?

names = ["Anu", "Ravi", "Meera"]
marks = [88, 92]
print(dict(zip(names, marks)))
  1. {'Anu': 88, 'Ravi': 92, 'Meera': None}
  2. {'Anu': 88, 'Ravi': 92}
  3. {'Anu': 88, 'Ravi': 92, 'Meera': 0}
  4. ValueError
Answer and explanation

Answer: B. {'Anu': 88, 'Ravi': 92}

Explanation: zip stops at the shortest input, so only two pairs are formed and "Meera" is dropped silently. No error is raised.

Previous: What will be the output of the following Python code? · Next: What will be the output of the following Python code?

Practise python

Try a fresh set of python questions with an explanation after every answer, free and without signing up: Python practice. Or sit a full placement mock test.

More python questions

More technical & programming practice

Data Structures · Algorithms · Object-Oriented Programming · DBMS · SQL · Operating Systems · Computer Networks · Software Engineering

LogicWiz Exams home · All practice topics · Placement mock tests · Daily 10 challenge