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])
  1. A. ['mon', 'wed'] 25 35
  2. B. ['mon', 'wed'] tue 35
  3. C. ['wed'] tue 35
  4. 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

Exams that ask this topic