ProgrammingModerateTCS NQT · Wipro pattern
What is printed?
What is printed?
pairs = list(zip([1, 2, 3], 'ab', [True])) print(pairs, len(list(zip())))
- A. [(1, 'a', True), (2, 'b', None)] 0
- B. [(1, 'a', True)] 0
- C. [(1, 'a', True)] 1
- D. [(1, 'a', True), (2, 'b', True)] 0
Correct answer: B. [(1, 'a', True)] 0
zip stops at the shortest iterable, here the one-element list, so only one tuple appears. zip with no arguments yields nothing, so its length is 0.
More Python Programming questions
- What is printed? python def threeless(a, t): a = sorted(a) n = len(a) c = 0 for i in range(n - 2): l, r = i + 1, n - 1 while l < r: if…
- What is printed? python import heapq def rooms(iv): iv = sorted(iv) h = [] for s, e in iv: if h and h[0] <= s: heapq.heapreplace(h, e)…
- For a Python dict d with n entries, which operation costs O(n) rather than O(1) on average?
- With n = 2 x 10^5 and a 1-second limit in CPython, which algorithm can be rejected because it is too slow?
- A solution loops over 2 x 10^5 queries, and each query runs if x in lst on a list of 2 x 10^5 items. Which change keeps the same answers…
- What is printed? python def tri(t): dp = t[-1][:] for row in range(len(t) - 2, -1, -1): for j in range(len(t[row])): dp[j] = t[row][j] +…