Lambda Syntax


languages = ["HTML", "JavaScript", "Python", "Ruby"]
print filter(lambda x: x == "Python", languages)

Is this right or I'm missing something here?


This is the right code, why are you asking?


I know it's just example, but It so useless typing "Python" again :smiley:


Then you copy paste it? Agree, this example isn't great, but this can be a great way to filter a list


You'll learn soon how lambdas can be used as a sort of condensed function.
I find it much more useful.

add = lambda x, y: x + y
add(1, 2)


Yeah! Looks really more of hard coding: How about?:

languages = ["HTML", "JavaScript", "Python", "Ruby"]
print filter(lambda x: x == languages[2], languages)


what about it? Of course, there are sometimes (most times actually) multiply ways to solve a problem


Sure there are.:smiley: