Skip to content

Instantly share code, notes, and snippets.

@amankharwal
Created Jan 31, 2021
Embed
What would you like to do?
# 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