Python Lambda Functions??

Поделиться
HTML-код
  • Опубликовано: 25 ноя 2024

Комментарии • 134

  • @thefoolishgmodcube2644
    @thefoolishgmodcube2644 Год назад +230

    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 Год назад +43

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

    • @Inf1e
      @Inf1e Год назад +8

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

    • @bamremix8235
      @bamremix8235 Год назад +33

      @@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 5 месяцев назад

      ​@@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.

  • @deanbond007
    @deanbond007 Год назад +184

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

    • @b001
      @b001  Год назад +29

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

  • @lindavid1975
    @lindavid1975 4 месяца назад +19

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

    • @Samreyna1
      @Samreyna1 2 месяца назад

      Makes you think, what he is playing piano with!

    • @davids7646
      @davids7646 5 дней назад

      Maybe a keyboard ​@@Samreyna1

  • @jackkraus6948
    @jackkraus6948 10 месяцев назад +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

  • @WibleWobble
    @WibleWobble Год назад +19

    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 👍

  • @TheRealKitWalker
    @TheRealKitWalker Год назад +44

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

  • @abhinavjoe
    @abhinavjoe Год назад +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.

  • @ElevateCode
    @ElevateCode Месяц назад +1

    Amazing explanation, straight to the point and covered what I needed. Thank you!

  • @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!!

  • @EricWAtchesVideos
    @EricWAtchesVideos 10 месяцев назад +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.

  • @robbertvandermeijden
    @robbertvandermeijden 7 месяцев назад +2

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

  • @ksspqf6016
    @ksspqf6016 Год назад +30

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

    • @MarleykHarbdul-xp9ez
      @MarleykHarbdul-xp9ez 6 месяцев назад

      That's your problem

    • @ksspqf6016
      @ksspqf6016 6 месяцев назад +14

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

    • @montagecentral1379
      @montagecentral1379 5 месяцев назад

      @@ksspqf6016 dedication

    • @ElijahWatts-ji9yx
      @ElijahWatts-ji9yx 4 месяца назад

      ​@ksspqf6016 you're probably over complicating it

    • @seancore1
      @seancore1 2 месяца назад

      @@MarleykHarbdul-xp9ez what is wrong with you

  • @FetchTheCow
    @FetchTheCow 10 месяцев назад

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

  • @davids7646
    @davids7646 5 дней назад

    That higher order function is eye opening now i understand.

  • @qayyax
    @qayyax 9 месяцев назад +1

    Thank you so much for this video.
    You are blessed

  • @avb5300
    @avb5300 2 месяца назад

    The music was an awesome touch, thanks a bunch

  • @mooseydev
    @mooseydev Месяц назад

    Excellent, concise, aesthetic explanation. Liked & subbed.

  • @handlemyece
    @handlemyece 7 месяцев назад +1

    Thank you for the video!

  • @alberthernandez5578
    @alberthernandez5578 11 месяцев назад

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

  • @Arsenit
    @Arsenit 18 дней назад

    Fantastically simple and quick!

  • @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 3 месяца назад

      @@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 ..

  • @yashwantdhole7645
    @yashwantdhole7645 Год назад

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

  • @tanmaypatel4152
    @tanmaypatel4152 Год назад +2

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

  • @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!

  • @jacksonmadison9994
    @jacksonmadison9994 10 месяцев назад +2

    Man, computer science is so difficult.

    • @veelone3663
      @veelone3663 3 месяца назад

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

  • @NeverSaid-
    @NeverSaid- 6 месяцев назад

    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]

  • @yrebrac
    @yrebrac 2 месяца назад

    love the concise explanation

  • @ninavanleeuwen1183
    @ninavanleeuwen1183 Год назад +1

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

  • @gaberg21
    @gaberg21 Год назад

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

  • @avgvstvs96
    @avgvstvs96 Год назад

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

  • @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?

  • @xeurek4
    @xeurek4 9 месяцев назад +1

    Nice explanation

  • @Liz4rdMan
    @Liz4rdMan 11 месяцев назад

    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.

  • @ArticlesGD
    @ArticlesGD 3 месяца назад +1

    lambda: HALF LIFE

  • @inteligenciaartificiuau
    @inteligenciaartificiuau 9 месяцев назад

    Amazing! Thanks!

  • @stephenburke7108
    @stephenburke7108 9 месяцев назад

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

  • @williamomon3894
    @williamomon3894 Год назад

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

  • @mirlamontano6640
    @mirlamontano6640 Год назад

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

  • @raylink1722
    @raylink1722 2 месяца назад

    Thank you so much

  • @sews1523
    @sews1523 9 месяцев назад

    awesome vid actually, thanks

  • @jirafey_
    @jirafey_ Год назад +2

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

  • @ironmonkey1990
    @ironmonkey1990 3 месяца назад

    thank you

  • @AHWAProductions
    @AHWAProductions Год назад

    man you explain it so well 😭

  • @heel57
    @heel57 4 месяца назад

    good explanation but the music is disturbing

  • @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)

  • @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.

  • @jakeaustria5445
    @jakeaustria5445 3 месяца назад

    Thanks

  • @radishark8449
    @radishark8449 9 месяцев назад

    Simple and useful tutorial❤

  • @amansjourneys2
    @amansjourneys2 8 месяцев назад

    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

  • @seanshimon
    @seanshimon 8 месяцев назад

    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))

  • @learningforever957
    @learningforever957 Год назад

    Thank you so much, perfectly explained

  • @Sdksakdjas
    @Sdksakdjas 7 месяцев назад

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

  • @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

  • @CAMPERRRR
    @CAMPERRRR 7 месяцев назад

    You need to keep making content

  • @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

  • @viktoreidrien7110
    @viktoreidrien7110 Год назад

    excellent explanation, thanks man

  • @ajflink
    @ajflink 5 месяцев назад

    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.

  • @MusicEffekt
    @MusicEffekt Год назад

    please make the font a bit larger. Thanks

  • @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

  • @CHUAN-CHI
    @CHUAN-CHI 10 месяцев назад

    Thank you

  • @carlosmillananhel2878
    @carlosmillananhel2878 Год назад

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

  • @dipeshsamrawat7957
    @dipeshsamrawat7957 Год назад

    Excellent ❤

  • @fcesteghlal
    @fcesteghlal 8 месяцев назад

    why music in the background?

  • @DiegoGomez-en7pn
    @DiegoGomez-en7pn Год назад

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

  • @baliDOTid
    @baliDOTid Год назад

    what's your vs code theme?

  • @dakookh
    @dakookh Год назад

    Jeez… Still can’t get it😢

  • @cother8312
    @cother8312 5 месяцев назад

    So it's like an arrow function in JavaScript?

  • @chaithanyav6646
    @chaithanyav6646 6 месяцев назад

    Brilliant

  • @itsm0saan
    @itsm0saan Год назад +1

    what is the font you are using.?

  • @Oliver-Zen
    @Oliver-Zen Год назад

    thanks!

  • @khucthuydu1991
    @khucthuydu1991 2 месяца назад

    Amazing

  • @oromogamer1431
    @oromogamer1431 Месяц назад

    So i used panda and its very slow with my code and large data and chatgpt gave me lambda function for some codes i want to understand the core concept behind it can you do a video on data analysis using lambda?

  • @francoli2281
    @francoli2281 Год назад

    what colour theme are you using?

  • @JustineEllyn
    @JustineEllyn 9 месяцев назад

    ... half-life.

  • @jonathanvioleta3578
    @jonathanvioleta3578 Год назад

    From my understanding, its basically a inline function ?

  • @karimjapparov5324
    @karimjapparov5324 Год назад

    thank you

  • @FazliddinSaydullayevbek
    @FazliddinSaydullayevbek 9 месяцев назад

    Your python is looks really beautiful how can i download that

  • @Fisal_Gamal_Elgendy_2002
    @Fisal_Gamal_Elgendy_2002 Год назад

    thanks

  • @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?

  • @hubertgrzymkiewicz8883
    @hubertgrzymkiewicz8883 Год назад

    awesome!!

  • @jaksiz
    @jaksiz 9 месяцев назад

    You're awesome

  • @barbellbilly
    @barbellbilly Год назад +1

    What vscode theme is this?

  • @sparetimes1215
    @sparetimes1215 3 месяца назад

    Good video, but don't add background music.

  • @Deveus-y4s
    @Deveus-y4s Год назад

    Salute to you.

  • @vladoxgz
    @vladoxgz Год назад

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

  • @neonblowfish
    @neonblowfish 6 месяцев назад

    Great video, but annoying music

  • @tsunningwah3471
    @tsunningwah3471 9 месяцев назад

    zhina

  • @Stefch2
    @Stefch2 4 дня назад

    Stop the music

  • @ego-lay_atman-bay
    @ego-lay_atman-bay Год назад +1

    What are lambda functions in python? Horse crap

  • @mirzaimadbaig
    @mirzaimadbaig Год назад

    nicely explained

  • @krapiak
    @krapiak 3 месяца назад

    what theme do you use??

  • @russ7k
    @russ7k Год назад

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

  • @Zaryan___Zaryan
    @Zaryan___Zaryan Год назад

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

  • @Fisal_Gamal_Elgendy_2002
    @Fisal_Gamal_Elgendy_2002 Год назад

    thanks