ProgrammingModerateTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
print(list(map(sum, zip([1, 2], [3, 4]))), list(zip(*[[1, 2], [3, 4]])))
- A. [3, 4] [(1, 3), (2, 4)]
- B. [4, 6] [[1, 4], [2, 3]]
- C. [4, 6] [(1, 3), (2, 4)]
- D. [4, 6] [(1, 2), (3, 4)]
Correct answer: C. [4, 6] [(1, 3), (2, 4)]
zip pairs the lists element-wise, so the sums are 1 + 3 and 2 + 4. zip(*) of the two rows transposes them into column tuples.
More Python Programming questions
- What is printed? python print(10 // 3 3 + 10 % 3 == 10, -10 // 3 3 + -10 % 3 == -10, 10 // -3 -3 + 10 % -3 == 10)
- What is printed? python print(0 == False, '' == False, [] == False, None == False)
- What is printed? python from collections import Counter print(Counter('hello').mostcommon(2))
- What is printed? python def keyfn(p): return (-p[1], p[0]) people = [('bo', 3), ('al', 5), ('cy', 3)] print([p[0] for p in sorted(people…
- What is printed? python s = 'abcabc' print(s.find('c'), s.find('c', 3), s.rfind('c', 0, 4), s.count('c', 2))
- What is printed? python nums = [1, 2, 3, 4, 5] print([nums[i] for i in range(len(nums) - 1, -1, -2)], nums[::-2][0])