6 examples of 'index of max element in list python' in Python

Every line of 'index of max element in list python' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
147@listfunc
148def max_index(args):
149 return args.index(builtins.max(args))
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

56def maximum(lst):
57 currMax = lst[0]
58 for val in lst[1:]:
59 if val > currMax: currMax = val
60 return currMax
51def posMin(list):
52 """ returns the index of the lowest value of a given list
53 if multiple highest values exist, the first is returned
54 """
55 m = list[0]
56 index = 0
57 for i, x in enumerate(list):
58 if x < m:
59 m = x
60 index = i
61 return index
5def max(data): # pylint: disable=redefined-builtin
6 """
7 This function returns the maximum numerical value in a data set.
8
9 Args:
10 data: A numeric built-in object or list of numeric objects.
11
12 Returns:
13 A numeric object.
14
15 Examples:
16 >>> max([1, 2, 3])
17 3
18 >>> max([-3, 0, 3])
19 3
20 >>> max([-2])
21 -2
22 >>> max(-3)
23 -3
24 """
25
26 if type(data) is list:
27 max_value = data[0]
28 for ii in data:
29 if ii > max_value:
30 max_value = ii
31 elif type(data) is int or type(data) is float:
32 max_value = data
33
34 return(max_value)
27def rindex(lst, item):
28 try:
29 return dropwhile(lambda x: lst[x] != item, reversed(xrange(len(lst)))).next()
30 except StopIteration:
31 raise ValueError, "rindex(lst, item): item not in list"
16def max_(seq):
17 if len(seq) == 2:
18 return seq[0] if seq[0] > seq[1] else seq[1]
19 sum_max = max_(seq[1:])
20 return seq[0] if seq[0] > sum_max else sum_max

Related snippets