How can I make a lambda expression to check for X?


How can I make a lambda expression to check for X?


The lambda we need to write consists of three key parts:

  1. The keyword lambda at the beginning: lambda … …
  2. The variable you want to operate on, followed by a colon: lambda var_name: …
  3. The variable expression, where you can check for condition to be met by your variable: lambda var_name: var_name == some_condition

If we want to check if our lambda’s variable is equal to the character ”X”, we’d do that in the third part of our lambda.

Something wrong with the result check here.

1 Like

Hi @npanop, and welcome to the Codecademy Forums!

For this exercise, you need to first assign the result to the variable message. Then you can do this:

print message

Link to exercise: Advanced Topics in Python: Lambda Expressions

Can’t say it’s the best approach to evaluate the code, as you force people to write the code your way, so to say.
For instance in this task the string wot’n be used anywhere else, so no point to store it.

@npanop, if you are planning to continue in Python as presented on Codecademy, then saving a result to a variable later to be printed is a technique you’ll need to get used to; right or wrong, you’ll find it used frequently in every course.

1 Like

Hello everyone. Please I need an assistance on my codecademy account, Please I am having issue with my account. Each time I try to log in, I will be getting a response that the user already exists. If I finally log in, it will bring a complete new account for me. Pls can you help to resolve this?

Talk better with support. There are two options; one that your account has been leaked and now someone is using it (something that is quite strange as you might not have a premium one) or that you are pressing register instead of log in. Anyways, if it’s none of those problems, talk better with support. They might have a mail or something I guess.

Hello! For this exercise can I also use n.pop() to remove “X” from the list please?

No definitely not because in this exercise we are learning lambdas and filtering , thus we cant use n.pop()
we can use n.pop() for other exercises but not for this