Lambda in Python - Advanced Python 08 - Programming Tutorial - Map Filter Reduce

preview_player
Показать описание
Lambda in Python - Advanced Python 08 - Programming Tutorial - Map Filter Reduce

In this Python Advanced Tutorial, we will be learning about Lambda functions in Python. A lambda function is a small (one line) anonymous function that is defined without a name. It is typically used when you need a simple function that is used only once in your code, or it is used as an argument to higher-order functions. We will go over how you define them, and some use cases together with the built-in sorted(), map(), filter,() and reduce() functions.

~~~~~~~~~~~~~~ GREAT PLUGINS FOR YOUR CODE EDITOR ~~~~~~~~~~~~~~

📚 Get my FREE NumPy Handbook:

📓 Notebooks available on Patreon:

A written Tutorial can be found here:

You can find me here:

#Python

----------------------------------------------------------------------------------------------------------
* This is a sponsored or an affiliate link. By clicking on it you will not have any additional costs, instead you will support me and my project. Thank you so much for the support! 🙏
Рекомендации по теме
Комментарии
Автор

Probably the best python tutorial in YT.

nemesis_rc
Автор

I researched about lambda functions but was still confused on how it was being used in the sort and sorted functions.
You covered it thankfully in this video, and it helped a lot, thanks!

TelepathShield
Автор

Really well presented; you conveyed the concepts extremely well.

cetilly
Автор

This is the best python tutorial i think. Thanks for giving free advance tutorial.

ProvlemSolveBangla
Автор

Thanks for the vid Patrick! This really helped me

bigspicydad
Автор

from functools import reduce

add_num = lambda x: x+10 #anonymous
print(add_num(5))

mul_num = lambda x, y: x*y
print(mul_num(5, 4))

points2D = [(1, 2), (15, 1), (5, -1), (10, 4)]
sort_points = sorted(points2D) #sort by x argument
print(sort_points)
sort_points = sorted(points2D, key=lambda x: x[1]) #lambda sort with y
print(sort_points)
sort_points = sorted(points2D, key=lambda x: x[0]+x[1]) #lambda sort sum
print(sort_points)

a = [1, 2, 3, 4]
b = list(map(lambda x: x*2, a)) #map iterable and lambda func + arr
print(b)
print([x*2 for x in a]) #list comprehension abbreviation

c = list(filter(lambda x: x % 2 == 0, a)) #filter -> bool + lambda + arr
print(c)
print([x for x in a if x % 2 == 0]) #list comprehension

d = reduce(lambda x, y: x*y, a) #product of list
print(d)

kvelez
Автор

Not quite an advanced course but extremely thorough and brilliantly presented. I've saved it so I can keep it as a reference.

rob
Автор

Thank you for making things simple to understand

geetak
Автор

Thank you! I needed a video on how to use these, as the docs didn’t make a whole lot of sense on my first read through. This has helped out a lot!

BbB-vruh
Автор

I found this Video the best, how is this Video dont have more likes and Views.

pkavenger
Автор

THANK IT WEAS SO CLEAR AND VERY HELPFUL!!

sohailaali
Автор

Hey Pal you deserve more than a million subs... dude u helped me a lot in the * operator video

raseshshetty
Автор

according to pep 8 we should not assign the lambda functions and use them as call backs, and when we want to name it use just def mul(x, y):return x*y is one liner and is fine, he only use case I saw somewhere was to assign it in a call back via walrus operator that was some application inside the function too

xzex
Автор

I would loved it more if you've covered the if and else inside lambda. But thank you for your efforts!

revolutionN
Автор

Thanks but i wish you addressed using lamda on a dataframe with apply and map. Getting the syntax right can be frustrating for newbies.

expat
Автор

It is possible to use Lambda with strings?

TKhan
Автор

The X We call it parameter or argument !

belgacem_mehdi
Автор

Hard to see a situation why reduce() is useful. Any suggestion?

orjihvy
Автор

Can I know what editor you are using? Thanks~

summerxia
Автор

Good content but lack clarity of what you want to achieve with each method. Especially when starting writing example it is not clear what you want to achieve which minimizes the value of content

srh