ProgrammingModerateTCS NQT · Infosys
What is printed?
What is printed?
print(list(zip('ab', [1, 2, 3])), dict(zip('ab', [1, 2, 3])))- A. [('a', 1), ('b', 2), ('x', 3)] {'a': 1, 'b': 2}
- B. [('a', 1), ('b', 2)] {'a': 1, 'b': 3}
- C. [('a', 1), ('b', 2)] {'a': 1, 'b': 2}
- 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
- What is printed? python print(sorted([('b', 1), ('a', 2), ('a', 1)])[1:], sorted({3: 'c', 1: 'a'}.items()))
- What is printed? python print(sorted({'b': 1, 'a': 2}), sorted({'b': 1, 'a': 2}.values(), reverse=True))
- What is printed? python print(len({x % 3 for x in range(10)}), sorted({x x % 5 for x in range(5)}))
- What is printed? python print(list(range(-5, 5, 4)), list(range(5, -5, -4)), range(-1, -4, -1)[0])
- What is printed? python print(int(-7 / 2), -7 // 2, int(7 / -2), 7 // -2)
- What is printed? python print(7 % 0.5, 7.25 % 0.5, -1 % 0.25)