Lambda expression

lambda.py


l = ['Mon','Tue','wed']
def change_words(words, func):
    for word in words:
        print(func(word))

#If you don't use a lambda expression
#def sample_func(word):
    #return word.capitalize()
#change_words(l,sample_func)

#You can write in one line using a lambda expression
change_words(l,lambda word:word.capitalize())

output:

Mon
Tue
Wed

Recommended Posts

Lambda expression
lambda expression memo
A python lambda expression ...
Use print in a Python2 lambda expression
python3x: lambda function
Regular expression Greedy
Conditional expression grouping
LoL ~ Lambda operate Lambda ~
Recursive expression memo
Regular expression re