Skip to content

Instantly share code, notes, and snippets.

@amankharwal
Created January 31, 2021 15:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amankharwal/ae3691e5dc6d3747a59c9ee14b20a002 to your computer and use it in GitHub Desktop.
Save amankharwal/ae3691e5dc6d3747a59c9ee14b20a002 to your computer and use it in GitHub Desktop.
# 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