Update and rename max_element_pos.md to max_element_index.md
This commit is contained in:
17
snippets/max_element_index.md
Normal file
17
snippets/max_element_index.md
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
---
|
||||||
|
title: max_element_index
|
||||||
|
tags: list,beginner
|
||||||
|
---
|
||||||
|
|
||||||
|
Returns the pindex of the element with the maximum value in a list.
|
||||||
|
|
||||||
|
Use `max()` and `list.index()` to get the maximum value in the list and return its index.
|
||||||
|
|
||||||
|
```py
|
||||||
|
def max_element_index(arr):
|
||||||
|
return arr.index(max(arr))
|
||||||
|
```
|
||||||
|
|
||||||
|
```python
|
||||||
|
max_element_index([5, 8, 9, 7, 10, 3, 0]) # 4
|
||||||
|
```
|
||||||
@ -1,17 +0,0 @@
|
|||||||
---
|
|
||||||
title: max_element_pos
|
|
||||||
tags: list,beginner
|
|
||||||
---
|
|
||||||
|
|
||||||
find the position of larger Element
|
|
||||||
|
|
||||||
using `list.index()` and `max()` function we can get the position of the max element in the list (for min element's possition change the `max()` to `min()`)
|
|
||||||
|
|
||||||
```py
|
|
||||||
def max_element_pos(arr):
|
|
||||||
return arr.index(max(arr)) + 1
|
|
||||||
```
|
|
||||||
|
|
||||||
```python
|
|
||||||
max_element_pos([5, 8, 9, 7, 10, 3, 0]) # 5
|
|
||||||
```
|
|
||||||
Reference in New Issue
Block a user