Python Lambda Functions??

Поділитися
Вставка
  • Опубліковано 27 вер 2024
  • ⭐ Join my Patreon: / b001io
    💬 Discord: / discord
    🐦 Follow me on Twitter: / b001io
    🔗 More links: linktr.ee/b001io
    Background Music:
    Gentle Lo-Fi Vlog Background Music | Cookies by Alex-Productions | onsound.eu/
    Music promoted by www.free-stock...
    Creative Commons / Attribution 3.0 Unported License (CC BY 3.0)
    creativecommon...

КОМЕНТАРІ • 127

  • @thefoolishgmodcube2644
    @thefoolishgmodcube2644 Рік тому +205

    Another thing is that lambda functions are faster to create and call compared to regular functions, so if you're obsessed with performance and your function only has a return statement you might as well make it a lambda function.

    • @steveman1982
      @steveman1982 Рік тому +27

      But then again, python isn't really the right tool, if you want speed.

    • @thefoolishgmodcube2644
      @thefoolishgmodcube2644 Рік тому +42

      @@steveman1982 Yeah, more reason why you should opt for the fastest Python code, to make up for its slowness.

    • @Inf1e
      @Inf1e Рік тому +6

      if you obsessed with performance you really shouldn't use Python in first place

    • @bamremix8235
      @bamremix8235 11 місяців тому +31

      @@Inf1ewell tbh most of the popular machine learning and deep learning modules are easily accessible through python. So saying performance should be ignored while using python is stupid

    • @ajflink
      @ajflink 4 місяці тому

      ​@@bamremix8235 Also, there are ways to make things faster and more efficient in Python if you know what you are doing. There are so many people that blame bad performance on Python yet have so much redundancy in their code that there is no surprise that things are bad performance wise or using a large amount of memory. The most infamous example that I can think of is ArcGIS Pro. If you know, you know. Also, since Python is not bound by strict typing, you can do crazy things not possible in most other languages.

  • @lindavid1975
    @lindavid1975 2 місяці тому +5

    Being able to play the piano whilst programming is a skill.

    • @Samreyna1
      @Samreyna1 8 днів тому

      Makes you think, what he is playing piano with!

  • @deanbond007
    @deanbond007 Рік тому +173

    Thank you for all the videos you make they're really informative and make learning so much easier

    • @b001
      @b001  Рік тому +26

      Wow, thank you so much! So generous of you! I'm glad you enjoy my content!

  • @WibleWobble
    @WibleWobble Рік тому +15

    its like you can read my mind, every time during the video i had a question, a second later you answered it. Well deserved sub 👍

  • @abhinavjoe
    @abhinavjoe 11 місяців тому +3

    My man not only explained me what lamda functions are, but also cleared my doubts about how the map() function works. Very informative and well put video. You're the best.

  • @avb5300
    @avb5300 5 днів тому

    The music was an awesome touch, thanks a bunch

  • @marclaygeorges2786
    @marclaygeorges2786 Рік тому +25

    Your Python videos are always clear and concise explanations with great examples. Thank you for making these videos!

    • @b001
      @b001  Рік тому +3

      Wow! Thank you so much! I’m so glad you enjoy them!!

  • @ksspqf6016
    @ksspqf6016 Рік тому +28

    That's all very nice but I'm too stupid to put that skill into practise

    • @MarleykHarbdul-xp9ez
      @MarleykHarbdul-xp9ez 4 місяці тому

      That's your problem

    • @ksspqf6016
      @ksspqf6016 4 місяці тому +13

      ​@MarleykHarbdul-xp9ez I've rewatched it again and now I'm even more confused than i was a year ago

    • @montagecentral1379
      @montagecentral1379 3 місяці тому

      @@ksspqf6016 dedication

    • @ElijahWatts-ji9yx
      @ElijahWatts-ji9yx 2 місяці тому

      ​@ksspqf6016 you're probably over complicating it

    • @seancore1
      @seancore1 20 днів тому

      @@MarleykHarbdul-xp9ez what is wrong with you

  • @qayyax
    @qayyax 7 місяців тому +1

    Thank you so much for this video.
    You are blessed

  • @FetchTheCow
    @FetchTheCow 8 місяців тому

    Thank you for the use case! I didn't get it after your lambda short, but now I do.

  • @FollowPathfinder
    @FollowPathfinder Рік тому +3

    Thank’s for the explanation. Lambda functions with map make things look so much easier, I wonder why is this even considered as intermediate Python knowledge?

    • @fabricehategekimana5350
      @fabricehategekimana5350 Рік тому

      I think it's because this concept belong to functional programming and go a bit deeper than what people thougth (It come from the lambda calculus). Generally people start with an imperative programming style, go to an object oriented programming style and maybe go to functional programming

    • @veelone3663
      @veelone3663 Місяць тому

      @@fabricehategekimana5350 huh ? im not even taking intermediate yet and lambda is being introduced rn. You're telling me it gets deeper than this? I'm fucked ..

  • @jacksonmadison9994
    @jacksonmadison9994 8 місяців тому +2

    Man, computer science is so difficult.

    • @veelone3663
      @veelone3663 Місяць тому

      literally taking programming rn and Idk wtf I'm doing lol

  • @sapogatowo
    @sapogatowo Рік тому +3

    Ow mannnn, your code-communication skills are truly amazing!
    One question, do you have in mind continuing the 'How 2 Python' series? If so, when are you dropping the next video?
    Hope you are having a great day uwu!

  • @chrysos
    @chrysos Рік тому +6

    why do u use brakets with ure return ?

    • @jojojux
      @jojojux Рік тому +3

      That triggered me too.

    • @b001
      @b001  Рік тому +4

      I saw that when editing the video. I'm not sure why I did that lol

  • @darss10
    @darss10 Рік тому +8

    Great video! Very simple and clear explanation!!
    I am currently learning tkinter and I was told that you can use the lambda keyword when assigning a command to a button -> button_1 = tkinter.Button(command=lambda: button_click()).
    What's the difference between using lambda and just assigning the function without lambda -> button_1 = tkinter.Button(command=button_click)??
    Thanks!

    • @chrysos
      @chrysos Рік тому +3

      tkinter takes functions as arguments and calls them with their own arguments. For example if u use .bind("", func) on the main window ure function gets call on press of the Return key (Enter) with ure mouse possitions and more as argumets. this does not matter for ure button command, because it provides no arguments. U can use both of ure examples, but if u want to provide ure own arguments u need to use lambda

    • @chrysos
      @chrysos Рік тому +2

      from tkinter import Tk, Button
      def func(*args):
      print(args)
      tk = Tk()
      tk.geometry("300x200")
      tk.bind("", func)
      button = Button( command=func)
      button.pack()
      tk.mainloop()

    • @chrysos
      @chrysos Рік тому +1

      run this code, click the button, press Enter and look at the output

    • @chrysos
      @chrysos Рік тому +1

      i am not a pro its just what i could understand myself

    • @darss10
      @darss10 Рік тому +1

      @@chrysos WOW thanks! So, if I need to pass arguments into my button command, I use lambda, is that it?

  • @tanmaypatel4152
    @tanmaypatel4152 Рік тому +2

    Great video as always! BTW, which font are you using? It is so elegant.

  • @xeurek4
    @xeurek4 7 місяців тому +1

    Nice explanation

  • @ninavanleeuwen1183
    @ninavanleeuwen1183 Рік тому +1

    thank you for the video, but the music is too loud for me!

  • @raylink1722
    @raylink1722 25 днів тому

    Thank you so much

  • @stephenburke7108
    @stephenburke7108 7 місяців тому

    you can lose lines 1-7 and just replace line 10 with: cubed = list(map(lambda x: x**3, nums))

  • @Liz4rdMan
    @Liz4rdMan 9 місяців тому

    It is also usable when you only use a function once so you won't need to create a whole function for it and no one will use it.

  • @ajflink
    @ajflink 4 місяці тому

    lambda is like decorator. They are useful tools but you are not severely crippling yourself by not using them.
    Due to what I am coding for and how I write Python code, I have never saw any need or desire to use decorators. I do see personal usage for lambda, though.

  • @mirlamontano6640
    @mirlamontano6640 Рік тому

    thank you for this video! very informative, useful and clear!! subscribed 💖

  • @jakeaustria5445
    @jakeaustria5445 Місяць тому

    Thanks

  • @heel57
    @heel57 2 місяці тому

    good explanation but the music is disturbing

  • @fcesteghlal
    @fcesteghlal 6 місяців тому

    why music in the background?

  • @seanshimon
    @seanshimon 6 місяців тому

    lambda vs not lambda:
    def my_map(my_func, my_iter) -> list:
    result = []
    for item in my_iter:
    new_item = my_func(item)
    result.append(new_item)
    return result
    nums = [3, 4, 5, 6]
    cube_using_lambda = my_map(lambda x: x**3, nums)
    print(cube_using_lambda)
    def my_func_cube(size: int) -> int:
    return size**3
    cube_func = my_func_cube
    print(my_map(cube_func, nums))

  • @CAMPERRRR
    @CAMPERRRR 5 місяців тому

    You need to keep making content

  • @williamomon3894
    @williamomon3894 11 місяців тому

    Hey man lovely vid , one question what extension got your IDE to look like that

  • @cother8312
    @cother8312 3 місяці тому

    So it's like an arrow function in JavaScript?

  • @AHWAProductions
    @AHWAProductions Рік тому

    man you explain it so well 😭

  • @tompov227
    @tompov227 Рік тому +1

    Your videos are really informative! What font do you use in your code editor, I really like it and I currently just use the default in mine

  • @neomimendoza8339
    @neomimendoza8339 Рік тому +1

    Hello! Could you please share your programming environment color scheme and your font? They're so easy on the eyes!

    • @ahbpoo
      @ahbpoo Рік тому +3

      I searched his previous comments, where someone asked this question, and they got the answer: SynthWave '84

  • @sews1523
    @sews1523 7 місяців тому

    awesome vid actually, thanks

  • @khucthuydu1991
    @khucthuydu1991 6 днів тому

    Amazing

  • @learningforever957
    @learningforever957 Рік тому

    Thank you so much, perfectly explained

  • @MusicEffekt
    @MusicEffekt 11 місяців тому

    please make the font a bit larger. Thanks

  • @FazliddinSaydullayevbek
    @FazliddinSaydullayevbek 7 місяців тому

    Your python is looks really beautiful how can i download that

  • @radishark8449
    @radishark8449 7 місяців тому

    Simple and useful tutorial❤

  • @JustineEllyn
    @JustineEllyn 7 місяців тому

    ... half-life.

  • @viktoreidrien7110
    @viktoreidrien7110 Рік тому

    excellent explanation, thanks man

  • @carlosmillananhel2878
    @carlosmillananhel2878 Рік тому

    for js people, as much as i understood lambda is the same that (params)=>{...}

  • @CHUAN-CHI
    @CHUAN-CHI 8 місяців тому

    Thank you

  • @baliDOTid
    @baliDOTid Рік тому

    what's your vs code theme?

  • @dakookh
    @dakookh Рік тому

    Jeez… Still can’t get it😢

  • @dipeshsamrawat7957
    @dipeshsamrawat7957 Рік тому

    Excellent ❤

  • @francoli2281
    @francoli2281 Рік тому

    what colour theme are you using?

  • @sreejishnair5922
    @sreejishnair5922 Рік тому

    Bro what keyboard do you use?

  • @ahbpoo
    @ahbpoo Рік тому

    What theme do you use?

  • @BroSience.c
    @BroSience.c Рік тому

    What vs code theme do you use?

  • @Fisal_Gamal_Elgendy_2002
    @Fisal_Gamal_Elgendy_2002 Рік тому

    thanks

  • @karimjapparov5324
    @karimjapparov5324 11 місяців тому

    thank you

  • @jaksiz
    @jaksiz 7 місяців тому

    You're awesome

  • @Deveus-y4s
    @Deveus-y4s Рік тому

    Salute to you.

  • @neonblowfish
    @neonblowfish 4 місяці тому

    Great video, but annoying music

  • @tsunningwah3471
    @tsunningwah3471 7 місяців тому

    zhina

  • @ego-lay_atman-bay
    @ego-lay_atman-bay Рік тому +1

    What are lambda functions in python? Horse crap

  • @mirzaimadbaig
    @mirzaimadbaig Рік тому

    nicely explained

  • @russ7k
    @russ7k Рік тому

    So, writing lambda functions are better than writing normal functions?

  • @Zaryan___Zaryan
    @Zaryan___Zaryan 11 місяців тому

    (💲10.00) thnaks your video is so best😀😀

  • @TheRealKitWalker
    @TheRealKitWalker Рік тому +42

    I simply love the fact, that how concise this video is. Fantastic. I finally Understood the dreaded lambda function. 💪 Thanks so much dude.

  • @Fisal_Gamal_Elgendy_2002
    @Fisal_Gamal_Elgendy_2002 Рік тому

    thanks

  • @jackkraus6948
    @jackkraus6948 8 місяців тому +3

    What I first used lambda functions for was when I created minesweeper in tkinter. The button components took a function parameter to call when pressed. Since in Minesweeper pressing an empty cell (no adjacent bombs, i.e. no number) reveals the cells around it, I wrote a recursive function that when given a row and column number revealed the cell value in that spot and called the function for the cells around it if the cell was empty. I used lambda to iteratively create functions using that function while passing in a set row and column.
    TL:DR you can use lambda to create a version of a defined function with filled in parameters

  • @ArticlesGD
    @ArticlesGD Місяць тому +1

    lambda: HALF LIFE

  • @robbertvandermeijden
    @robbertvandermeijden 5 місяців тому +1

    perfect video. Straight to the point and told me everything I needed to know. Thanks!

  • @EricWAtchesVideos
    @EricWAtchesVideos 8 місяців тому +1

    Thank you for the clear explanation!!
    I think that like so many of these language features, they solve a problem that doesn't exist.
    It's nice to have features, but I doubt that I will end up using this ever.

  • @jirafey_
    @jirafey_ Рік тому +2

    Did you ever make content online? You seem to be professional asf

  • @handlemyece
    @handlemyece 5 місяців тому +1

    Thank you for the video!

  • @sparetimes1215
    @sparetimes1215 Місяць тому

    Good video, but don't add background music.

  • @itsm0saan
    @itsm0saan Рік тому +1

    what is the font you are using.?

  • @Sdksakdjas
    @Sdksakdjas 5 місяців тому

    what vscode theme do u use i really like this one!

  • @yrebrac
    @yrebrac 25 днів тому

    love the concise explanation

  • @ironmonkey1990
    @ironmonkey1990 Місяць тому

    thank you

  • @chaithanyav6646
    @chaithanyav6646 4 місяці тому

    Brilliant

  • @NeverSaid-
    @NeverSaid- 4 місяці тому

    This looks like a security vulnerability waiting to happen.
    And this whole example can be reduced to 2 lines of code:
    Nums =[3,4,5,6,7]
    Cubed = [item**3 for item in Nums]

  • @epsi
    @epsi Рік тому

    my_map = lambda my_func, my_iter: (my_func(x) for x in my_iter)
    cubed = list(my_map(lambda x: x**3, nums))
    Generators are great, except when they're not.

  • @amansjourneys2
    @amansjourneys2 6 місяців тому

    Thank you for this! My follow up question would be wouldnt it be easier to create a for loop to cube "nums" and add it to a list called "cubed"?? I'm not seeing how using lambda was faster/easier here

  • @jonathanvioleta3578
    @jonathanvioleta3578 10 місяців тому

    From my understanding, its basically a inline function ?

  • @DiegoGomez-en7pn
    @DiegoGomez-en7pn Рік тому

    What software do you use to record your videos and shorts?

  • @yashwantdhole7645
    @yashwantdhole7645 Рік тому

    My goodness. This is the best and concise explanation of dreaded lambda function

  • @avgvstvs96
    @avgvstvs96 Рік тому

    dont stop Sir Bool, these videos breath life into my soul

  • @alberthernandez5578
    @alberthernandez5578 9 місяців тому

    Well this was easy to follow, thank you for the videos bro, they really help out

  • @gaberg21
    @gaberg21 Рік тому

    you explained it super well! will be sending this video to friends who dont get it

  • @barbellbilly
    @barbellbilly Рік тому +1

    What vscode theme is this?

  • @inteligenciaartificiuau
    @inteligenciaartificiuau 7 місяців тому

    Amazing! Thanks!

  • @hubertgrzymkiewicz8883
    @hubertgrzymkiewicz8883 11 місяців тому

    awesome!!

  • @Oliver-Zen
    @Oliver-Zen Рік тому

    thanks!

  • @magic_cow
    @magic_cow Рік тому +1

    In a thing I’m working on, I used lambda functions and assigned them to a variable, because they allowed my to put some a if else statement onto 1 line instead of 5 lines, this was amazing since this allowed me to bring 15 lines of codes down to 3 lines of code
    UPDATE: I put the lambda functions into the things that were calling it, now I am saving 3 more lines of code. Yippie!
    Function format:
    (Line 1: defining function
    Line 2: if statement
    Line 3: run function
    Line 4: else statement
    Line 5: run diffrent function)

  • @vladoxgz
    @vladoxgz Рік тому

    cubed = [n**3 for n in nums]

  • @krapiak
    @krapiak Місяць тому

    what theme do you use??