Python lambda, map, filter, & reduce - Higher Order Functions for Beginners

Sdílet
Vložit
  • čas přidán 24. 07. 2024
  • Web Dev Roadmap for Beginners (Free!): bit.ly/DaveGrayWebDevRoadmap
    Learn Python lambda, map, filter, & reduce in this beginners tutorial on Higher Order Functions. Python lambda function expressions can be used with map, filter, and reduce for efficient and clean code.
    💖 Support me on Patreon ➜ / davegray
    ⭐ Become a full-stack dev with Zero To Mastery Courses:
    - The Complete Python Developer: bit.ly/CompPythonDev
    - Complete Machine Learning & Data Science: bit.ly/CompMachineLearning
    - Junior to Senior Dev Roadmap: bit.ly/WebDevRoadmap-JrtoSr
    🚩 Subscribe ➜ bit.ly/3nGHmNn
    📬 Course Updates ➜ courses.davegray.codes/
    ❓ Questions - Please post them to my Discord ➜ / discord
    ☕ Buy Me A Coffee ➜ www.buymeacoffee.com/davegray
    👇 Follow Me On Social Media:
    Github: github.com/gitdagray
    Twitter: / yesdavidgray
    LinkedIn: / davidagray
    🔗 Source Code: github.com/gitdagray/python-c...
    🔗 Playlist for this Python Course: bit.ly/dg-beginners-python
    Python lambda, map, filter, & reduce - Higher Order Functions for Beginners
    (00:00) Intro
    (00:05) Welcome
    (00:14) What is a lambda?
    (00:32) Lambda function expression examples
    (06:02) When to use lambda expressions
    (08:40) What are Higher Order Functions?
    (10:01) map() function
    (12:19) filter() function
    (14:56) reduce() function
    (16:57) Avoid reduce if a simple solution exists
    (18:41) More complex reduce example
    📚 Tutorial References:
    🔗 Python Official Site: www.python.org/
    🔗 Visual Studio Code Official Site: code.visualstudio.com/
    🔗 Python Module Index: docs.python.org/3/py-modindex...
    🔗 Python Standard Library: docs.python.org/3/library/ind...
    Was this Python higher order functions tutorial helpful? If so, please share. Let me know your thoughts in the comments.
    #python #lambda #map

Komentáře • 30

  • @xzex2609
    @xzex2609 Před 9 měsíci +2

    he is such a great teacher and I actually am learning JS from his channel . and even though I know python for years still enjoying to see his way of teaching. thanx

  • @Leesdjo
    @Leesdjo Před rokem

    Thank you Dave. I have learned lots from you as a student when I first found out about your CZcams channel. Thank you for your kindness.

  • @OneStopMusic.
    @OneStopMusic. Před měsícem

    great and to the point explanation

  • @insteresting
    @insteresting Před 8 měsíci +1

    Very nice tutorial, Dave!

  • @TannerBarcelos
    @TannerBarcelos Před rokem +2

    I feel like seeing this in JavaScript before Python helps folks understand it even better. Sure, lambda arg: are a little different than ()=> but given Python isn’t functional in nature, I noticed many folks find this to be confusing. You did an awesome job explaining it!

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  Před rokem

      Thank you!

    • @xzex2609
      @xzex2609 Před 9 měsíci

      once you see its actual use cases (call backs ,....) you will find that the lambda is a very effective tool you can't do without , maybe that's why pep-8 recommends that lambda should not be assigned ,cause its own use cases are very special , like in GUI programming if a widget need to pass one or two parameters to a function , you can not use a function for that unless you wrap your function inside an otter function that calls inner function to have a return value , but a simple lambda expression will save the day and you don't need to even define a function even if your command is a function like print( argument) you can't use () in your command= in your widget and you had to wrap the print inside a function otherwise print returns None but by using lambda you simply can use Button(......, command=lambda:print('string')) or command = lambda event:print(event).
      otherwise you got to use a higher order function (nested wrapper / inner) function

  • @sonamohialdin3376
    @sonamohialdin3376 Před rokem

    Very helpful tutorial thank you very much

  • @aniruddhadas2953
    @aniruddhadas2953 Před rokem

    Thank You,Sir.

  • @alexanderkomanov4151
    @alexanderkomanov4151 Před rokem

    Thanks!

  • @danielurbanowicz7882
    @danielurbanowicz7882 Před 3 měsíci

    Solution for reformat lambda by vs code is to put parentheses around the lambda assignment: squared = (lambda num: num * num) 😃

  • @obiemmanuel354
    @obiemmanuel354 Před rokem

    I love your contents a lot sir

  • @xzex2609
    @xzex2609 Před 9 měsíci

    According to PEP-8 anonymous functions better not assign to a variable their use is more like call backs like arr.sort(key = lambda data:data[0]) and other stuff like that. but visual studio doesn't apply the pep-8 unless you install an extension. I remember the extension was very annoying , but now see it as a tool to learn pep 8 standards in the action to write better code.

  • @xzex2609
    @xzex2609 Před 9 měsíci

    once you see its actual use cases (call backs ,....) you will find that the lambda is a very effective tool you can't do without , maybe that's why pep-8 recommends that lambda should not be assigned ,cause its own use cases are very special , like in GUI programming if a widget need to pass one or two parameters to a function , you can not use a function for that unless you wrap your function inside an otter function that calls inner function to have a return value , but a simple lambda expression will save the day and you don't need to even define a function even if your command is a function like print( argument) you can't use () in your command= in your widget and you had to wrap the print inside a function otherwise print returns None but by using lambda you simply can use Button(......, command=lambda:print('string')) or command = lambda event:print(event).
    otherwise you got to use a higher order function (nested wrapper / inner) function

  • @ggff2269
    @ggff2269 Před rokem +2

    Hey Dave, i am facing very slow compilation time in nextjs . A single change in file takes upto 60 seconds to appear and takes upto 2.5 gbs of ram. Also i am not using additional packages. I have noticed 1000s of devs facing same issue. How do you encounter this? It is very frustrating. It should have to be fast like vite. 😭😭😭 I really started hating it now but have to use it for SEO 😭😭😭😭

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  Před rokem +1

      Duplicate question and this time on a Python video?? I answered under the appropriate Next.js video.

  • @latesttrendzs
    @latesttrendzs Před rokem

    Hey dave ! Just curious to know how coding teachers on CZcams like you get there knowledge from. Where they get to know so details of those coding languages?

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  Před rokem +2

      Documentation, books, other articles and tutorials, and experience - no secret or shortcut here. I teach at university and the same applies there.

  • @johnaweiss
    @johnaweiss Před 6 měsíci

    6:00 Would be helpful if your commented lambda rewrites inluded the var name as you had originally entered. Without the var name, the commented lambdas are not equivalent to the defs.

  • @netronominom2850
    @netronominom2850 Před rokem

    Your videos are amazing
    Is it possible to make a tutorial for decentralized crypto exchange?

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  Před rokem +1

      Thank you! I have not gotten into crypto coding. There are some good channels for that.

  • @utinthein7274
    @utinthein7274 Před rokem

    Thank you, sir

  • @johnaweiss
    @johnaweiss Před 6 měsíci

    1:34 My vscode doesn't do this conversion, so i'm guessing you have a formatter extension installed, such as "black". So that's not a native vscode behavior.
    15:01 My vscode doesn't move imports to the top. Again, i'm guessing you have a formatter extension.

  • @JHunterJoe
    @JHunterJoe Před 10 měsíci

    it re formatting because your not calling the lamda function right