Lambdas

# An anonymous function that does not have a name
# Can have any number of arguments but can only have one expression 

# Create a lambda 
add_4 = lambda x : x + 4 

print(add_4(4))

# Lambda that takes two arguments 
add = lambda x, y: x + y 

# Break a string into blocks
blocks = lambda x,y: [x[i:i+y]] for i in range(0, len(x),y)
print(blocks("string", 2 ))

Last updated