# FAQ: Learn Python - Advanced Topics in Python - Anonymous Functions

This community-built FAQ covers the “Anonymous Functions” exercise in Codecademy’s lessons on Python.

## Join the Discussion. We Want to Hear From You!

Agree with a comment or answer? Like () to up-vote the contribution!

Want to take the conversation in a totally different direction? Join our wider discussions.

Found a bug? Report it!

Have a question about your account, billing, Pro, or Pro Intensive? Reach out to our support team!

None of the above? Find out where to ask other questions here!

Not seeing your question? It may still have been asked before – try () in the top-right of this page. Still can’t find it? Ask it below by hitting the reply button below this post ().

## Other FAQs

• This list will contain other frequently asked questions that aren’t quite as popular as the ones above.
• This FAQ is built and maintained by you, the Codecademy community – help yourself and other learners like you by contributing!

Hi there. I’d just like to say that the definition of functional programming presented in this lesson is incorrect.
A few references:

https://www.quora.com/What-is-functional-programming

Cheers

So the instructions for this exercise say that:

print filter(lambda x: x % 3 == 0, my_list)

is the same as:

def by_three(x):
return x % 3 == 0

If however we call the my_list variable (my_list = range(16) into either of these functions, the conventional function (def by_three(x)) throws an error.

So is Codecademy incorrect here? If it’s the same then they should both print [0,3,6,9,12,15] right?

I went on to play around with def by_three(x) a bit more and a few more things have confused me.

So this prints the same numbers as the lamda function above:

def by_three(x):
for i in x:
if i % 3 == 0:
print i
by_three(my_list)

This next example however just prints 0. Why?

for i in x:
if i % 3 == 0:
return i
print by_three(my_list)

Thank you for your help. I really should understand these differences by now but apparently I don’t!

Kind regards,
Alex

I’ve only been able to glance at these lessons but the instructions state that just `lambda x: x% 3 == 0` was equivalent to the function definition.

Adding the filter function and passing it that lambda object and your iterable is quite different. The correct equivalence would be- `filter(by_three, my_list)`.

Your loop will not perform as expected because the return statement will execute on 0 and the function will exit (no other numbers would be checked). The simplest way would be to use filter as expected but you could perhaps look at generator functions (which I think would be closer to the logic you’re using) though they may not have come up in lessons. Best to stick with what you’re at and mark it as something to look at in the future.

As an additional it’d be worth looking at the following FAQ which describes how to format code which would make it much easier to understand as it respects indentations and such.

Thanks tgrtim,
That helps to clarify things a bit. I’ll be sure to check out those FAQs!
Thanks again,
Alex

For anyone else really confused on what exactly filter does and how this all works this website gives a good explanation Python filter()