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...
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!
Thank you!
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!
Thank you!
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.
Hi fred, are u going to release python deep dive part 5. if yes then what all topics you will cover?
No immediate plans at the moment...
I actually watch your videos on my iPhone mini 😂
(And enjoying it, of course)
hehe, don't know how you do it - I have dual 32" monitors, couldn't live without them! 😀
thank You as always
My pleasure!
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!
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.
you've already a with statement inside of the function. why do you need an extra "with" when calling the function ?
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.