From 8618cf89437fd44578c951e01f4c4879c3e3d824 Mon Sep 17 00:00:00 2001 From: manHoos786 <65845474+manHoos786@users.noreply.github.com> Date: Thu, 1 Oct 2020 16:36:52 +0530 Subject: [PATCH] Update Largest-element-of-a-list.md --- Loop-Related/Largest-element-of-a-list.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Loop-Related/Largest-element-of-a-list.md b/Loop-Related/Largest-element-of-a-list.md index 334774a..4cd8ff0 100644 --- a/Loop-Related/Largest-element-of-a-list.md +++ b/Loop-Related/Largest-element-of-a-list.md @@ -9,6 +9,7 @@ Take the first element as the largest number. Then loop through the list and com ## Solution +## Method 1- ```python def get_largest(nums): largest = nums[0] @@ -23,6 +24,17 @@ largest = get_largest(my_nums) print('The largest number is: ', largest) ``` +## Method 2- +```python +//we can easily use a function called max + +my_nums = [0,1,2,5,7,4,9] + +largest = max(my_nums) + +print('The largest number is: ', largest) +``` + **[Try it on Programming Hero](https://play.google.com/store/apps/details?id=com.learnprogramming.codecamp)** ## Explanation