Built-ins & Standard Library · Question 11 · Medium

max is called on a dictionary of city temperatures, once plainly and once with key=temps.get. What is printed?

temps = {"Pune": 31, "Shimla": 12, "Chennai": 35}
print(max(temps), max(temps, key=temps.get))
  1. Chennai Chennai
  2. Shimla 35
  3. Shimla Chennai
  4. 35 Chennai
Answer and explanation

Answer: C. Shimla Chennai

Explanation: Iterating a dictionary gives its keys, so plain max compares the names alphabetically and Shimla is last. With key=temps.get each name is compared by its temperature, and Chennai has the highest, 35.

Previous: A deque gets an appendleft, a pop and a rotate(1). What does it hold at the end? · Next: zip is used with the * operator to split a list of pairs. What does this code…

Practise built-ins & standard library

Try a fresh set of built-ins & standard library questions with an explanation after every answer, free and without signing up: Built-ins & Standard Library practice. Or sit a full placement mock test.

More built-ins & standard library questions

More python practice

Variables, Types & Operators · Python Strings · Lists & Tuples · Dictionaries & Sets · Conditions & Loops · Functions & Scope · Comprehensions & Generators · Classes & Objects

LogicWiz Exams home · All practice topics · Placement mock tests · Daily 10 challenge