Skip to content

Instantly share code, notes, and snippets.

@vinaykudari
Created July 21, 2018 20:51
Show Gist options
  • Save vinaykudari/05bbadb295d40e67f952496425dba3a3 to your computer and use it in GitHub Desktop.
Save vinaykudari/05bbadb295d40e67f952496425dba3a3 to your computer and use it in GitHub Desktop.
Reduce function
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