human
I am working on the file "Python/Python Morsels/multimax/Trey's Solutions/multimax.ipynb".
The first task is:
Bonus3: multimax function accept a keyword argument called "key" that is a function which will be used to determine the key by which to compare values as maximums
Can you write Python program for it?
 ... Give me a Python program to determine the key by which to compare values as maximums?
assistant
#Here is Python program to determine the key by which to compare values as maximums
.

def multimax(iterable, key=None):
    """ Return a list of all maximum values """
    if key is None:
        def key(item): return item
        
    maximums = []
    key_max = None
    
    for item in iterable:
        k = key(item)
        
        if k == key_max:
            maximums.append(item)
        elif not maximums or k > key_max:
            key_max = k
            maximums = [item]          
            
    return maximums        

multimax([1, 2, 4, 3])

multimax([1, 4, 2, 4, 3])

numbers = [1, 3, 8, 5, 4, 10, 6]
odds = (n for n in numbers if n % 2 == 1)

multimax(odds)

multimax([])

words = ["cheese", "shop", "ministry", "of", "silly", "walks", "argument", "clinic"]

multimax(words, key=len)