countlist = list(countlist.values())
Then the max function is legal on countlist (as shown on line 11).
The text on page 140 should read
Recall that the values() method returns a dict_values object which can be turned into a list by applying the list function.
Actually, the max() function can be applied to any iterable, including a dict_values object as well as a list. So although the name countlist would be a misnomer without the use of list(), and although the text on page 140 wasn't right, the code actually does work as given.
ReplyDeleteI think the line of code should read:
ReplyDeletecountlist = list(countdict.values())
since "countlist" has not been defined until this lines executes.