-
-
Save amankharwal/ae3691e5dc6d3747a59c9ee14b20a002 to your computer and use it in GitHub Desktop.
This file contains 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
# Lambda | |
s=lambda x:x*x | |
s(2) | |
# Map | |
def addition(n): | |
return n + n | |
numbers = (1, 2, 3, 4) | |
result = map(addition, numbers) | |
print(list(result)) | |
# Reduce | |
import functools | |
def mult(x,y): | |
print("x=",x," y=",y) | |
return x*y | |
fact=functools.reduce(mult, range(1, 10)) | |
print(fact) | |
# Filter | |
seq = [0, 1, 2, 3, 5, 8, 13] | |
result = filter(lambda x: x % 2 != 0, seq) | |
print(list(result)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment