Processing Dictionaries With min() and max()
00:45 The only difference between this example and the previous one is that the code is more explicit and clear about what you’re doing. Anyone reading the code quickly will realize that you want to find the smallest and largest keys in the input dictionary.
Python compares tuples item by item. For example, to determine if
(x1, x2) is greater than
(y1, y2), Python first tests if
x1 is greater than
y1. If this is true, then Python concludes that the first tuple is greater than the second without checking the rest of the items. In contrast, if
x1 is less than
y1, then Python concludes that the first tuple is less than the second. However, if
x1 is equal to
y1, then Python compares the second pair of items using the same rules.
02:17 Note that in this context, the first item of each tuple comes from the dictionary keys, and because dictionary keys are unique, the items can’t be equal, so Python will never have to compare the second values.
Become a Member to join the conversation.