bessarabov
0
Q:

return max value in list python

a.index(max(a))
1
my_dict = {'a': 5, 'b': 10, 'c': 6, 'd': 12, 'e': 7}
max(my_dict, key=my_dict.get) # returns 'd'
1
# any list
a = [1, 7, 3, 12, 5]

# index of minimum element
# if more than 1 minimum, 
# first index is returned
min_index = a.index(min(a))

# index of maximum element
max_index = a.index(max(a))
2
import numpy as np

x=[1,2,3,4,5]

max_index=np.argmax(x) 
# return the index of the maximun element
# max_index has the value 4 
1
li=[0,70,7,89]
max(li)
#gives the max value 89
2
# find largest item in the string
print(max("abcDEF")) 

# find largest item in the list
print(max([2, 1, 4, 3])) 

# find largest item in the tuple
print(max(("one", "two", "three"))) 
'two'

# find largest item in the dict
print(max({1: "one", 2: "two", 3: "three"})) 
3

# empty iterable causes ValueError
# print(max([])) 

# supressing the error with default value
print(max([], default=0)) 
1
max(list)
0

New to Communities?

Join the community