From 8a46cbdc26cfb302d92d823f79d16f90e5bbb658 Mon Sep 17 00:00:00 2001 From: Shubham Lad Date: Tue, 22 Oct 2019 00:29:28 +0530 Subject: [PATCH 1/3] program to find index of large number in list --- snippets/max_element_pos.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 snippets/max_element_pos.md diff --git a/snippets/max_element_pos.md b/snippets/max_element_pos.md new file mode 100644 index 000000000..27384a07b --- /dev/null +++ b/snippets/max_element_pos.md @@ -0,0 +1,17 @@ +--- +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 +``` + +```py +max_element_pos([5, 8, 9, 7, 10, 3, 0]) # 5 +``` \ No newline at end of file From 4ff3d8ae61c8435e39bf0070eda9695d8aa818ad Mon Sep 17 00:00:00 2001 From: Shubham Lad Date: Tue, 22 Oct 2019 00:37:32 +0530 Subject: [PATCH 2/3] program to find index of large number in list --- snippets/max_element_pos.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snippets/max_element_pos.md b/snippets/max_element_pos.md index 27384a07b..a03c92a5a 100644 --- a/snippets/max_element_pos.md +++ b/snippets/max_element_pos.md @@ -12,6 +12,6 @@ def max_element_pos(arr): return arr.index(max(arr)) + 1 ``` -```py +```python max_element_pos([5, 8, 9, 7, 10, 3, 0]) # 5 ``` \ No newline at end of file From 6696821735356c148c690eefe810ffb881cd9ab5 Mon Sep 17 00:00:00 2001 From: Angelos Chalaris Date: Thu, 31 Oct 2019 09:42:21 +0200 Subject: [PATCH 3/3] Update and rename max_element_pos.md to max_element_index.md --- snippets/max_element_index.md | 17 +++++++++++++++++ snippets/max_element_pos.md | 17 ----------------- 2 files changed, 17 insertions(+), 17 deletions(-) create mode 100644 snippets/max_element_index.md delete mode 100644 snippets/max_element_pos.md diff --git a/snippets/max_element_index.md b/snippets/max_element_index.md new file mode 100644 index 000000000..d500e0dac --- /dev/null +++ b/snippets/max_element_index.md @@ -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 +``` diff --git a/snippets/max_element_pos.md b/snippets/max_element_pos.md deleted file mode 100644 index a03c92a5a..000000000 --- a/snippets/max_element_pos.md +++ /dev/null @@ -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 -``` \ No newline at end of file