Max () i am stuck


I am stuck on the max ()


The max() function is used to find a maximum value contained in a list.

    values = [7,3,5,9,2,3,1]

    print (max(values))    # <-  9

Given that characters all have an ordinal, we can use the function to find the highest ordinal in a string or list of characters.

>>> values = ['a','b','c','d','e']
>>> max(values)
>>> max("the letter with the highest ordinal")

We can even use the function on dictionaries. By default, it will compare keys and return the one with the highest ordinal. To find the highest value, we pass the dict.values()…

>>> dict_items = {'a': 1, 'b': 2, 'c': 3, 'd': 4}
>>> max(dict_items)
>>> max(dict_items.values())


thanks for the help on max


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.