Lambda In The Learn Python 3 Course

The Learn Python 3 course should include lambda expressions, since the Learn Python 2 course has it.

It usually appears as a component of the iterators unit since they use anonymous functions in their callback.

>>> arr = [2, 3, 4, 5, 6, 7, 8, 9]
>>> arr2 = map(lambda x: x ** 2, arr)
>>> arr2
<map object at 0x000001B841B0F520>
>>> [*arr2]
[4, 9, 16, 25, 36, 49, 64, 81]

They also turn up in other higher-order function examples such as factory functions.

>>> def get_exp(a):
	return lambda x: x ** a

>>> get_squares = get_exp(2)
>>> [*map(get_squares, arr)]
[4, 9, 16, 25, 36, 49, 64, 81]

If you have completed the Learn Python 3 course and this never came up, then the course should be updated, agreed.


I have completed the Learn Python 3 course and lambda never came up.


I’d support this because lambda is still a feature of Python3 and you will find it used fairly regularly in actual code whether or not you like it. Since the usage is already covered in the Python2 course perhaps it’d be easier to add in?

@mtf’s usage of map would also be a good addition since it also winds up in plenty of Python3 code.

At the risk of derailing what was a simple and useful suggestion-

A more general introduction to Python’s iterator protocol and basic functional programming options might be a good addition somewhere. So far as I know it’s not actually included in any course (if anyone can correct me on that that would be appreciated).

Some information on zip, the __iter__ and __next__ dunder methods and generators would be a decent start. Even if you don’t implement them yourself knowing the background is worthwhile since so many built-ins rely on then and even Python’s for loops rely on iterators.

Articles noting more advanced options like the itertools module could round the topic out.

1 Like

A post was split to a new topic: What is map actually? How do I use it?

Problem solved; now the Learn Intermediate Python 3 course has it and I am up to the Functions Deep Dive topic(It teaches lambda, higher order functions and built in higher order ones). :grinning:

1 Like

Now I have the ability to understand that code(I learnt about function arguments which helped me on this part:

, the researching , the Learn Intermediate Python 3 course helped me on this:

and the Deep Dive: Functions topic in the Learn Intermediate Python 3 Course:


Does it actually; it appeared in the functions part?

Well, a lambda is a function, after all. Common usage is as a callback in iterator functions.

1 Like

Is it also known as a generator function?