ProgrammingModerateGATE CS · Product-company placement
What is printed?
What is printed?
temps = {"mon": 30, "tue": 25, "wed": 35}
hot = [d for d, t in temps.items() if t > 28]
coolest = min(temps, key=temps.get)
print(hot, coolest, sorted(temps.values())[-1])- A. ['mon', 'wed'] 25 35
- B. ['mon', 'wed'] tue 35
- C. ['wed'] tue 35
- D. ['mon', 'wed'] tue 30
Correct answer: B. ['mon', 'wed'] tue 35
items() yields (key, value) pairs; min with key=temps.get compares values but returns the key. Sorting the values puts the largest last.
More Python Programming questions
- What is printed? python s = "level" t = "".join(reversed(s)) u = s[::-1] print(s == t == u, t is s, list(reversed([1, 2])) == [2, 1]…
- What is printed? python marks = [72, 85, 64, 85, 90] print(marks.index(85), marks.count(85), sorted(marks)[len(marks) // 2]…
- What is printed? python inventory = {"pen": 3, "ink": 0} inventory["pad"] = inventory.get("pad", 0) + 5 inventory.update(ink=2)…
- What is printed? python def area(w, h=None): if h is None: h = w return w h print(area(3), area(3, 4), area(h=2, w=5), area([2, 6]))
- What is printed? python q = [1, 2, 3] stack = [1, 2, 3] print(q.pop(0), stack.pop(), q, stack, q + stack)
- What is printed? python s = "2024-01-15" y, m, d = map(int, s.split("-")) print(y + m + d, f"{d:02d}/{m:02d}/{y}", s[5:7] == "01")