ProgrammingHardCodeforces-style · placement coding round
What is printed?
What is printed?
def find(g, t):
for i, row in enumerate(g):
for j, v in enumerate(row):
if v == t:
break
else:
continue
return (i, j)
return None
print(find([[1, 2], [3, 4]], 3), find([[1, 2], [3, 4]], 9))- A. (1, 0) None
- B. (1, 1) None
- C. (0, 0) None
- D. (1, 0) (1, 1)
Correct answer: A. (1, 0) None
The inner break skips its else clause, so the function returns the position where the value was found. The outer loop's else with continue handles rows that have no match.
More Python Programming questions
- What is printed? python from functools import totalordering @totalordering class V: def init(self, n): self.n = n def eq(self, o): return…
- What is printed? python def make(): memo = {} def fib(n): if n in memo: return memo[n] memo[n] = n if n < 2 else fib(n - 1) + fib(n - 2)…
- What is printed? python words = 'the cat and the dog and the end'.split() cnt = {} for w in words: cnt[w] = cnt.get(w, 0) + 1 top =…
- What is printed? python def merge(iv): iv.sort() out = [iv[0]] for s, e in iv[1:]: if s <= out[-1][1]: out[-1][1] = max(out[-1][1], e)…
- What is printed? python import heapq def dijk(g, s): d = {s: 0} h = [(0, s)] while h: du, u = heapq.heappop(h) if du > d[u]: continue for…
- What is printed? python from collections import deque def topo(n, edges): indeg = [0] n adj = [[] for in range(n)] for u, v in edges…