Created
July 21, 2018 20:51
-
-
Save vinaykudari/05bbadb295d40e67f952496425dba3a3 to your computer and use it in GitHub Desktop.
Reduce function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import functools #reduce() is in functools package | |
lis = [1, 3, 5, 6, 2] | |
def get_greater(a,b): | |
if(a>b): | |
return a | |
else: | |
return b | |
f1 = functools.reduce(lambda a,b : a if a > b else b,lis) #using lambda function | |
f2 = functools.reduce(get_greater, lis) #using normal function | |
>> f1 | |
6 | |
>> f2 | |
6 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment