From e65b6b2f68b545dbb37c65904c8cf962d93c6d8f Mon Sep 17 00:00:00 2001 From: Varun Upadhyay Date: Fri, 27 May 2016 06:38:08 +0530 Subject: [PATCH 1/5] Create Python-Function-MIN.md --- Python-Function-MIN.md | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 Python-Function-MIN.md diff --git a/Python-Function-MIN.md b/Python-Function-MIN.md new file mode 100644 index 0000000000..45616d7588 --- /dev/null +++ b/Python-Function-MIN.md @@ -0,0 +1,36 @@ +# Python min(x) + +`min()` is a built-in function in Python 3. It returns the smallest item in an iterable or the smallest of two or more arguments. + +## Arguments +This function takes 2 or more numbers or any kind of iterable as an argument. While giving an iterable as an argument we must make sure +that all the elements in the iterable are of same type. This means that we cannot pass a list which has both string and integer values +stored in it. + +## Return Value + +The smallest item in the iterable is returned. If two or more positional arguments are provided, the smallest of the positional arguments +is returned. If the iterable is empty and default is not provided, a ValueError is raised. + +## Code Sample + +```python +print(min(2, 3)) # Returns 2 as 2 is the smallest of the two values +print(min(2, 3, -1)) # Returns -1 as -1 is the smallest of the two values + +list1 = [1, 2, 4, 5, -54] +print(min(list1)) # Returns -54 as -54 is the smallest value in the list + +list2 = ['a', 'b', 'c' ] +print(min(list2)) # Returns 'a' as 'a' is the smallest in the list in alphabetical order + +list3 = [1, 2, 'abc', 'xyz'] +print(min(list3)) # Gives TypeError as values in the list are of different type + +list4 = [] +print(min(list4)) # Gives ValueError as the argument is empty +``` + +:rocket: [Run Code](https://repl.it/CVir) + +[Official Docs](https://docs.python.org/3/library/functions.html#min) From 01bfd09e3e47fb117b21deb24311844726d6d47a Mon Sep 17 00:00:00 2001 From: Varun Upadhyay Date: Fri, 27 May 2016 13:02:14 +0530 Subject: [PATCH 2/5] Update Python-Function-MIN.md --- Python-Function-MIN.md | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/Python-Function-MIN.md b/Python-Function-MIN.md index 45616d7588..bf00fb4614 100644 --- a/Python-Function-MIN.md +++ b/Python-Function-MIN.md @@ -3,9 +3,20 @@ `min()` is a built-in function in Python 3. It returns the smallest item in an iterable or the smallest of two or more arguments. ## Arguments -This function takes 2 or more numbers or any kind of iterable as an argument. While giving an iterable as an argument we must make sure -that all the elements in the iterable are of same type. This means that we cannot pass a list which has both string and integer values -stored in it. +This function takes two or more numbers or any kind of iterable as an argument. While giving an iterable as an argument we must make sure that all the elements in the iterable are of same type. This means that we cannot pass a list which has both string and integer values stored in it. + +Valid Arguments: +```python +min(2, 3) +min([1, 2, 3]) +min('a', 'b', 'c') +``` +Invalid Arguments: +```python +min(2, 'a') +min([1, 2, 3, 'a']) +min([]) +``` ## Return Value From a06ad12de1bd7fc199324eb6a7c864dbd51ed7cc Mon Sep 17 00:00:00 2001 From: Varun Upadhyay Date: Fri, 27 May 2016 13:12:04 +0530 Subject: [PATCH 3/5] Update Python-Function-MIN.md --- Python-Function-MIN.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Python-Function-MIN.md b/Python-Function-MIN.md index bf00fb4614..60789f507a 100644 --- a/Python-Function-MIN.md +++ b/Python-Function-MIN.md @@ -3,7 +3,7 @@ `min()` is a built-in function in Python 3. It returns the smallest item in an iterable or the smallest of two or more arguments. ## Arguments -This function takes two or more numbers or any kind of iterable as an argument. While giving an iterable as an argument we must make sure that all the elements in the iterable are of same type. This means that we cannot pass a list which has both string and integer values stored in it. +This function takes two or more numbers or any kind of iterable as an argument. While giving an iterable as an argument we must make sure that all the elements in the iterable are of the same type. This means that we cannot pass a list which has both string and integer values stored in it. Valid Arguments: ```python @@ -38,6 +38,8 @@ print(min(list2)) # Returns 'a' as 'a' is the smallest in the list in alphabetic list3 = [1, 2, 'abc', 'xyz'] print(min(list3)) # Gives TypeError as values in the list are of different type +#Fix the TypeError mentioned above first + list4 = [] print(min(list4)) # Gives ValueError as the argument is empty ``` From 598a0eaed766ee0c38e0b0bdda34626c6f54c8b8 Mon Sep 17 00:00:00 2001 From: Varun Upadhyay Date: Fri, 27 May 2016 13:14:07 +0530 Subject: [PATCH 4/5] Update Python-Function-MIN.md --- Python-Function-MIN.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Python-Function-MIN.md b/Python-Function-MIN.md index 60789f507a..a0043059b9 100644 --- a/Python-Function-MIN.md +++ b/Python-Function-MIN.md @@ -44,6 +44,6 @@ list4 = [] print(min(list4)) # Gives ValueError as the argument is empty ``` -:rocket: [Run Code](https://repl.it/CVir) +:rocket: [Run Code](https://repl.it/CVir/3) [Official Docs](https://docs.python.org/3/library/functions.html#min) From cd817c0d161148880d3267b287083dfb3eb6b7e0 Mon Sep 17 00:00:00 2001 From: Varun Upadhyay Date: Fri, 27 May 2016 13:15:08 +0530 Subject: [PATCH 5/5] Update Python-Function-MIN.md --- Python-Function-MIN.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Python-Function-MIN.md b/Python-Function-MIN.md index a0043059b9..86fb01d3bc 100644 --- a/Python-Function-MIN.md +++ b/Python-Function-MIN.md @@ -38,12 +38,12 @@ print(min(list2)) # Returns 'a' as 'a' is the smallest in the list in alphabetic list3 = [1, 2, 'abc', 'xyz'] print(min(list3)) # Gives TypeError as values in the list are of different type -#Fix the TypeError mentioned above first +#Fix the TypeError mentioned above first before moving on to next step list4 = [] print(min(list4)) # Gives ValueError as the argument is empty ``` -:rocket: [Run Code](https://repl.it/CVir/3) +:rocket: [Run Code](https://repl.it/CVir/4) [Official Docs](https://docs.python.org/3/library/functions.html#min)