ProgrammingModerateGATE CS · Product-company placement
What is printed?
What is printed?
scores = [("a", 50), ("b", 80), ("c", 65)]
passed = [n for n, s in scores if s >= 60]
top = max(scores, key=lambda t: t[1])[0]
print(passed, top, dict(scores)["c"])- A. ['b', 'c'] 80 65
- B. [80, 65] b 65
- C. ['b', 'c'] b 65
- D. ['a', 'b', 'c'] b 65
Correct answer: C. ['b', 'c'] b 65
Unpacking each pair into n and s lets the comprehension filter by score and keep the name. max with a key returns the whole tuple, from which [0] picks the name. dict() accepts a list of pairs.
More Python Programming questions
- What is printed? python x = 7 kind = "even" if x % 2 == 0 else "odd" sign = "pos" if x > 0 else "zero" if x == 0 else "neg" print(kind…
- What is printed? python count = 0 for i in range(1, 4): for j in range(i): if (i + j) % 2: continue count += 1 print(count, i, j)
- What is printed? python a = [4, 2, 7] b = a b.sort() c = sorted(a, reverse=True) print(a, c, a is b, c is a)
- What is printed? python s = "banana" print(s.replace("a", "o", 2), s.upper().count("A"), s[::2], s.startswith(("x", "ba")))
- What is printed? python d = {"x": [1, 2], "y": [3]} flat = [v for vs in d.values() for v in vs] lengths = {k: len(v) for k, v in…
- What is printed? python def f(n): out = [] while n: n, r = divmod(n, -2) if r < 0: n, r = n + 1, r + 2 out.append(str(r)) return…