Python Lambda functions

# You can write small anonymous function with Lambda:

exclamation = (lambda a : a + '!')
exclamation('hello')

echo = (lambda word, e: word*e)
echo('hello',5)


# MAP() WITH LAMBDA FUNCTIONS
# map() applies a function over an object

l = ['a', 'b', 'c', 'd']
exclamation2 = map(lambda a : a+'!', l)
print(list(exclamation2))


# FILTER() WITH LAMBDA FUNCTIONS
# filter() is for filter out elements from a list that don't satisfy certain criteria

l = ['hello', 'hi', 'ciao', 'hola', 'marhabaan', 'hallo', 'alo']
longer = filter(lambda a : len(a) > 4, l)
print(list(longer))


# REDUCE() WITH LAMBDA FUNCTIONS
# reduce() is useful for performing some computation on a list and returns a single value

from functools import reduce
l = ['hello', 'hi', 'ciao', 'hola', 'marhabaan', 'hallo', 'alo']
result = reduce(lambda a, b : a + b, l)
print(result)



1 comment:

  1. We might permanently block any 카지노 user who abuses these situations. As of June 15, 2022, feedback on DenverPost.com are powered by Viafoura, and you might must log in again to start commenting. If you need assistance or are having points with your commenting account, please email us at

    ReplyDelete