Python Lambda Functions??

แชร์
ฝัง
  • เผยแพร่เมื่อ 21 ก.พ. 2023
  • ⭐ 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-music.com
    Creative Commons / Attribution 3.0 Unported License (CC BY 3.0)
    creativecommons.org/licenses/...
  • วิทยาศาสตร์และเทคโนโลยี

ความคิดเห็น • 105

  • @deanbond007
    @deanbond007 ปีที่แล้ว +159

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

    • @b001
      @b001  ปีที่แล้ว +22

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

  • @thefoolishgmodcube2644
    @thefoolishgmodcube2644 ปีที่แล้ว +178

    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 ปีที่แล้ว +25

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

    • @thefoolishgmodcube2644
      @thefoolishgmodcube2644 ปีที่แล้ว +35

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

    • @Inf1e
      @Inf1e ปีที่แล้ว +5

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

    • @bamremix8235
      @bamremix8235 8 หลายเดือนก่อน +27

      @@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 21 วันที่ผ่านมา

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

  • @WibleWobble
    @WibleWobble ปีที่แล้ว +12

    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 👍

  • @ksspqf6016
    @ksspqf6016 ปีที่แล้ว +22

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

    • @MarleykHarbdul-xp9ez
      @MarleykHarbdul-xp9ez หลายเดือนก่อน

      That's your problem

    • @ksspqf6016
      @ksspqf6016 หลายเดือนก่อน +5

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

  • @FetchTheCow
    @FetchTheCow 5 หลายเดือนก่อน

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

  • @abhinavjoe
    @abhinavjoe 7 หลายเดือนก่อน +2

    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.

  • @TheRealKitWalker
    @TheRealKitWalker ปีที่แล้ว +40

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

  • @qayyax
    @qayyax 4 หลายเดือนก่อน

    Thank you so much for this video.
    You are blessed

  • @robbertvandermeijden
    @robbertvandermeijden 2 หลายเดือนก่อน

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

  • @alberthernandez5578
    @alberthernandez5578 5 หลายเดือนก่อน

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

  • @EricWAtchesVideos
    @EricWAtchesVideos 5 หลายเดือนก่อน

    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.

  • @handlemyece
    @handlemyece 2 หลายเดือนก่อน

    Thank you for the video!

  • @mirlamontano6640
    @mirlamontano6640 ปีที่แล้ว

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

  • @jackkraus6948
    @jackkraus6948 5 หลายเดือนก่อน +1

    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

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

  • @gaberg21
    @gaberg21 ปีที่แล้ว

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

  • @marclaygeorges2786
    @marclaygeorges2786 8 หลายเดือนก่อน +23

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

    • @b001
      @b001  8 หลายเดือนก่อน +2

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

  • @inteligenciaartificiuau
    @inteligenciaartificiuau 4 หลายเดือนก่อน

    Amazing! Thanks!

  • @tanmaypatel4152
    @tanmaypatel4152 ปีที่แล้ว +1

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

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

  • @viktoreidrien7110
    @viktoreidrien7110 ปีที่แล้ว

    excellent explanation, thanks man

  • @sews1523
    @sews1523 4 หลายเดือนก่อน

    awesome vid actually, thanks

  • @avgvstvs96
    @avgvstvs96 ปีที่แล้ว

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

  • @yashwantdhole7645
    @yashwantdhole7645 9 หลายเดือนก่อน

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

  • @learningforever957
    @learningforever957 11 หลายเดือนก่อน

    Thank you so much, perfectly explained

  • @jacksonmadison9994
    @jacksonmadison9994 5 หลายเดือนก่อน +1

    Man, computer science is so difficult.

  • @dipeshsamrawat7957
    @dipeshsamrawat7957 ปีที่แล้ว

    Excellent ❤

  • @williamomon3894
    @williamomon3894 7 หลายเดือนก่อน

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

  • @xeurek4
    @xeurek4 4 หลายเดือนก่อน +1

    Nice explanation

  • @radishark8449
    @radishark8449 4 หลายเดือนก่อน

    Simple and useful tutorial❤

  • @AHWAProductions
    @AHWAProductions 10 หลายเดือนก่อน

    man you explain it so well 😭

  • @CHUAN-CHI
    @CHUAN-CHI 5 หลายเดือนก่อน

    Thank you

  • @chaithanyav6646
    @chaithanyav6646 หลายเดือนก่อน

    Brilliant

  • @DiegoGomez-en7pn
    @DiegoGomez-en7pn 11 หลายเดือนก่อน

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

  • @Sdksakdjas
    @Sdksakdjas 2 หลายเดือนก่อน

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

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

  • @CAMPERRRR
    @CAMPERRRR หลายเดือนก่อน

    You need to keep making content

  • @ninavanleeuwen1183
    @ninavanleeuwen1183 11 หลายเดือนก่อน +1

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

  • @amansjourneys2
    @amansjourneys2 3 หลายเดือนก่อน

    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

  • @NeverSaid-
    @NeverSaid- หลายเดือนก่อน

    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]

  • @Oliver-Zen
    @Oliver-Zen 8 หลายเดือนก่อน

    thanks!

  • @FollowPathfinder
    @FollowPathfinder ปีที่แล้ว +2

    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 9 หลายเดือนก่อน

      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

  • @sreejishnair5922
    @sreejishnair5922 ปีที่แล้ว

    Bro what keyboard do you use?

  • @hubertgrzymkiewicz8883
    @hubertgrzymkiewicz8883 7 หลายเดือนก่อน

    awesome!!

  • @itsm0saan
    @itsm0saan ปีที่แล้ว +1

    what is the font you are using.?

  • @Fisal_Gamal_Elgendy_2002
    @Fisal_Gamal_Elgendy_2002 11 หลายเดือนก่อน

    thanks

  • @MusicEffekt
    @MusicEffekt 8 หลายเดือนก่อน

    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

  • @karimjapparov5324
    @karimjapparov5324 7 หลายเดือนก่อน

    thank you

  • @francoli2281
    @francoli2281 ปีที่แล้ว

    what colour theme are you using?

  • @baliDOTid
    @baliDOTid ปีที่แล้ว

    what's your vs code theme?

  • @BroSience.c
    @BroSience.c ปีที่แล้ว

    What vs code theme do you use?

  • @ahbpoo
    @ahbpoo ปีที่แล้ว

    What theme do you use?

  • @fcesteghlal
    @fcesteghlal 2 หลายเดือนก่อน

    why music in the background?

  • @jirafey_
    @jirafey_ ปีที่แล้ว +2

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

    • @Adaephonable
      @Adaephonable 9 หลายเดือนก่อน

      This video is inline content...

  • @jaksiz
    @jaksiz 4 หลายเดือนก่อน

    You're awesome

  • @FazliddinSaydullayevbek
    @FazliddinSaydullayevbek 3 หลายเดือนก่อน

    Your python is looks really beautiful how can i download that

  • @Liz4rdMan
    @Liz4rdMan 6 หลายเดือนก่อน

    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.

  • @dakookh
    @dakookh 9 หลายเดือนก่อน

    Jeez… Still can’t get it😢

  • @stephenburke7108
    @stephenburke7108 4 หลายเดือนก่อน

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

  • @cother8312
    @cother8312 5 วันที่ผ่านมา

    So it's like an arrow function in JavaScript?

  • @jonathanvioleta3578
    @jonathanvioleta3578 7 หลายเดือนก่อน

    From my understanding, its basically a inline 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.

  • @magic_cow
    @magic_cow 9 หลายเดือนก่อน +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)

  • @user-yn1yo4eb6v
    @user-yn1yo4eb6v 9 หลายเดือนก่อน

    Salute to you.

  • @chrysos
    @chrysos ปีที่แล้ว +5

    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

  • @mirzaimadbaig
    @mirzaimadbaig ปีที่แล้ว

    nicely explained

  • @JustineEllyn
    @JustineEllyn 4 หลายเดือนก่อน

    ... half-life.

  • @ajflink
    @ajflink 21 วันที่ผ่านมา

    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.

  • @seanshimon
    @seanshimon 3 หลายเดือนก่อน

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

  • @carlosmillananhel2878
    @carlosmillananhel2878 ปีที่แล้ว

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

  • @barbellbilly
    @barbellbilly ปีที่แล้ว +1

    What vscode theme is this?

    • @cvntdav
      @cvntdav ปีที่แล้ว +1

      Synthwave '84

    • @barbellbilly
      @barbellbilly ปีที่แล้ว

      @@cvntdav Thank you so much!

  • @tsunningwah3471
    @tsunningwah3471 4 หลายเดือนก่อน

    zhina

  • @neonblowfish
    @neonblowfish 22 วันที่ผ่านมา

    Great video, but annoying music

  • @vladoxgz
    @vladoxgz ปีที่แล้ว

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

  • @ego-lay_atman-bay
    @ego-lay_atman-bay ปีที่แล้ว +1

    What are lambda functions in python? Horse crap

  • @wispaz1
    @wispaz1 9 หลายเดือนก่อน

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

  • @Zaryan___Zaryan
    @Zaryan___Zaryan 8 หลายเดือนก่อน

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

  • @Fisal_Gamal_Elgendy_2002
    @Fisal_Gamal_Elgendy_2002 11 หลายเดือนก่อน

    thanks