Max () i am stuck


#1

I am stuck on the max ()


#2

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)
'e'
>>> max("the letter with the highest ordinal")
'w'
>>> 

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)
'd'
>>> max(dict_items.values())
4
>>> 

#3

thanks for the help on max


#4

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