Idiomatic Python: Generators

แชร์
ฝัง
  • เผยแพร่เมื่อ 1 ส.ค. 2024
  • In this video we take a look at how to write more Pythonic code by leveraging generator expressions and functions.
    Most iteration related functions in Python are essentially generators (like zip, enumerate, islice, and many many more).
    There's a reason for that, and we also explore those reasons in this video.
    #mathbyteacademy #python
    Content
    =======
    00:00 - Introduction
    00:19 - Generator expressions
    09:32 - Using itertools.islice
    12:00 - Generator functions
    15:00 - Context managers
    18:26 - Generator based context managers
    25:50 - Review of CSV readers and writers
    28:51 - CSV application of generator based context managers
    36:34 - Context managers conclusion
    37:31 - Conclusion
    Code for this Video
    ===================
    Available in GitHub blog repo: github.com/fbaptiste/python-blog
    Direct link: tinyurl.com/34jdxhd8
    My Python Courses
    =================
    - Python 3 Fundamentals (introduction to Python)
    www.udemy.com/course/python3-...
    - Python 3 Deep Dive (Part 1 - Functional)
    www.udemy.com/course/python-3...
    - Python 3 Deep Dive (Part 2 - Iteration, Generators)
    www.udemy.com/course/python-3...
    - Python 3 Deep Dive (Part 3 - Hash Maps)
    www.udemy.com/course/python-3...
    - Python 3 Deep Dive (Part 4 - OOP)
    www.udemy.com/course/python-3...

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

  • @nitin.cherian
    @nitin.cherian 11 หลายเดือนก่อน

    As always, succinct!. Thank you Fred. Once again, I was able to embrace the powerful features of Python that make the code beautiful and easy to read!

  • @alfreroble6624
    @alfreroble6624 11 หลายเดือนก่อน +2

    Fred thank you so much for sharing your knowledge, I'm a student in engineering and I love your lessons (currently going through deep dive part 2 :D ). I wish you the best in life!

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

      Thank you!

    • @MohamedAhmed-rf5bk
      @MohamedAhmed-rf5bk 11 หลายเดือนก่อน +2

      Trust me it gets so much better, I’m in part 3. I would watch Fred after coming from a full time Job…. And I never once got bored.

  • @adilkhatri7475
    @adilkhatri7475 ปีที่แล้ว +7

    Hi fred, are u going to release python deep dive part 5. if yes then what all topics you will cover?

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

      No immediate plans at the moment...

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

    I actually watch your videos on my iPhone mini 😂
    (And enjoying it, of course)

    • @mathbyteacademy
      @mathbyteacademy  ปีที่แล้ว +3

      hehe, don't know how you do it - I have dual 32" monitors, couldn't live without them! 😀

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

    thank You as always

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

    I'm currently going through itertools in Part 2 Deep dive.
    Is this a sensible ordering? Any suggestions for the starred steps?
    1. Complete Part 2 Deep Dive
    *: ?
    2. Watch this video
    *: ?
    3. Part 3 Deep Dive
    *: ?
    4. Part 4 Deep Dive
    *: ?
    No need to respond if you think most orderings are equally good. I doubt I'd choose an obviously bad ordering, so my common sense can probably be relied on. But any input would be valued!

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

      Deep dive should probably be done in order. This channel is not a "companion" to my Udemy courses, and as such there is no particular order to any of these videos - i basically create them based on what I feel like recording, so completely ad hoc.

  • @yt-1161
    @yt-1161 9 หลายเดือนก่อน

    you've already a with statement inside of the function. why do you need an extra "with" when calling the function ?

    • @mathbyteacademy
      @mathbyteacademy  9 หลายเดือนก่อน +1

      the function is a context manager, so it is used with a `with` statement. But the function itself, uses another context manager, to open files, hence why it also uses a `with` statement. Two different context managers.