10 examples of 'find index of max element in list python' in Python

Every line of 'find 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
59def list_find(l, element):
60 for i, e in enumerate(l):
61 if e == element:
62 return i
63 return None
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
4def find(arr, elem):
5 lo = 0
6 hi = len(arr) - 1
7 while lo < hi:
8 mid = (hi + lo) // 2
9 first = arr[lo]
10 middle = arr[mid]
11 last = arr[hi]
12
13 if first <= middle and elem >= first and elem <= middle:
14 return binary_search(arr, elem, lo, mid)
15 elif last >= middle and elem >= middle and elem <= last:
16 return binary_search(arr, elem, mid+1, hi)
17 elif elem >= first and elem <= middle:
18 hi = mid
19 else:
20 lo = mid + 1
21
22 if arr[lo] == elem:
23 return lo
24 return None
62def find_index(self, e):
63 for i in range(self._size):
64 if self._data[i] == e:
65 return i
66 return -1
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"
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)
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
5def max(a):
6 max_elem = a[0]
7 for element in a[1:]:
8 if element > max_elem:
9 max_elem = element
10 return max_elem

Related snippets