Lambda Syntax


#1

https://www.codecademy.com/en/courses/python-beginner-en-KAgt5/3/2?curriculum_id=4f89dab3d788890003000096#

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

Is this right or I'm missing something here?


#2

This is the right code, why are you asking?


#3

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


#4

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


#5

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)

#6

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

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

#7

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


#8

Sure there are.:smiley: