@@Holphana You’re right, I just didn’t choose my words carefully enough. What I mean is that the presentation is that of a factual text, instead of creating unnecessary clutter through adding emotion or emphasis like so many other TH-camrs do.
What's really missing is a title card with a photo of M with chin in hands looking puzzle, or head-in-hands despairing at some topic that was exhorted in many keynote talks - TDD, say
Mate, I have years of Python experience, yet everytime you release a video I am floored by some of the stuff you showcase and I feel like I'm learning about the language for the first time. Stellar job, as always, and your presentation style is excellent for the job.
I swear every time I start watching a video on this channel I think “ah here is another thing I already know in python I probably won’t learn anything new this topic is pretty straight forward” and I end the video feeling like I never knew anything about it to begin with 😂😂 keep up the great work
Async (vs threading vs "other kinda-multitasking methods") video would be greatly appreciated. It's not the most useful stuff for your average script or simple program, so I rarely see good explanations of it for any language.
I write things like "sum(x for x in range(10))" very often and I didn't know that was generator comprehension! I was thinking it was the same as writing "sum([x for x in range(10)])" (with brackets). Thanks a lot for your content!
That’s the difference between an “iterator” and an “iterable”. An “iterable” has an ‗‗iter‗‗ method, which returns an iterator when it is called. The iterator is what returns the elements of the sequence, until it is exhausted and can’t be called again. Because range() is an iterable, you can reuse a single range object to return any number of iterators over that range.
Very insightful video! One other place I've seen generators used frequently is for API pagination. If, for instance, if you want to get all 100 records from an API, and the API limits your query to 10 records per call, you may not want to wait for all 10 calls. Instead you create a generator that calls the API only when you've completed working with the first page and are ready to move onto the second, etc.
Database queries is a good example. A very common sequence is * Create a cursor object * Execute a query on the cursor * Iterate over the results returned from the cursor * Close the cursor. You can wrap all these steps up in a single generator function, which takes the query and lets you iterate over the results in a single step.
Outstanding video as always. itertools might have deserved a mention since it is very useful with generators. The jump from iterator to coroutine was a bit steep and I would personally love an async video
This is why I like your channel: Even when I think I know a topic well, I still expect to find something new in your videos, and I always do. Keep it up!
Yep, definitely interested in an async video. Especially interested in learning the "python native" async features and components so as to detangle it from all the third-party contributed stuff.
Just as I was about to suggest a video on async, James announced it himself. 👍🏻 Can't wait to see this convoluted topic explained in mCoding simple comprehensible manner.
Great video. It was eye opening for me when I learnt about generator comprehension. I realised that I was doing something very inefficient passing list comprehensions to sum and other functions. Also worker example is amazing. Never used it this way.
Watched this video because I'm like, "I know what generators are, but I bet I'll learn something new about them." Found out that yield is an expression. Mind blown. Not disappointed. Please make the async video.
Thank you so much for this video, and all of others. I've started reading Fluent Python a couple months ago, but that was quite hard for me to go through it. And you on your channel describe those hard for me things and I finally get them somehow. Thought I was dumb, but all i needed was to find a great lecturer. Thank you so much!
I probably only got 20% of this video. But it was enough for me to fiddle around and learn more about generators' daily use cases to improve my performance... Great video, Mcoding 😄
I think this will really help me with lazy execution via generators. This would have really helped if . Also, 'yield from' was hard for me to get from just the docs, so thanks for summing that up tidily.
This video is definitely eye-opening. I thought that generators were just regular functions that you could re-enter, but I never comprehended how python calls them totally differently. Adding something like "if False: yield" to a regular function totally changes how it is called, despite those 2 lines of code being a noop.
I watched quite few videos about async but I would still like your take as well. It is one of the more complicated/complex? parts of the language to grasp.
Very nice CTA at the end, hadn't noticed it before, clever :) Otherwise great video and can't wait to know how async uses generators, I've been curious about that ever since you mentioned it a while ago.
not just imagination or/and downloadspeed but also your pride deciding what you appropriate from the interwebs or what you painstakingly program yourself in most likely a less efficient methode.
ALL hail @mcoding High Priest of the Python temple!! Your explanations are succinct, and the usage examples help me so much to grasp the concepts. Thank you.
Plot twist: The 1 Gb file you're trying to read, has only 1 line xD Awesome video. The send method confuses me a lot every time I see it, I don't know why lol
I am a fan of generators. I use "yield from" when the function that generates the next thing happens to be recursive. For example, I have a generator that takes a list of N things, and yields each permutation of those N things, and the underlying algorithm is recursive.
> "Do you think, they would really introduce a whole new set of keywords just to have a shortened for-loop?" Yes. The answer is "Yes, I can see the Python devs do that."
Can you do a video on making __iter__ a generator vs defining a __next__? I’ve seen both in the wild, you seem preferential to the __iter__ generator, and I’ve googled to no avail. I’m mostly interested in which one is more pythonic, but I’d also like to know what you think the use cases for each are. Great videos!
I enjoy your dives under the hood of stuff I routinely use and thought I knew well. It might be worth pointing out that generator comprehensions can have closures like functions can: def multiples(value): return (value * x for x in [1, 2, 3]) fives = multiples(5) for number in fives: # 5 is now embedded in fives print(number) TH-cam comments need code formatting markup. At least on this channel.
4:44 what is this _make method you call? I wasn't expecting this code to run, but it still did, even though it doesn't appear you defined the method? Is this something generated by dataclass?
Note that MyDataPoint class is the type NamedTuple. I googled for "_make NamedTuple Python" and got some info on the function. Turns out that _make is part of the NamedTuple class.
Also note that's its a NamedTuple and not a data class. This just means that you have different functions that you can use. So no comparison, like you do with data classes. You CAN do it, but you'll have to implement it yourself.
@@NostraDavid2 I see, thanks for pointing it out. So, I'm not sure why I thought it was a dataclass, but I guess I just saw the type annotations and didn't read the top part. That makes a lott more sense, big thanks :)
Do you think it would be a good idea for the else clause in the for/in/else loop to be the place where the generator's returned value is made available?
Hooray for Python and yield from. Because the code smelled like it wanted to do that and Python does it. I only know C#, which has "generators", and yielding "from" is an obvious thing one would want to do.
Haha welcome to my channel! A lot of my videos are guilty of this. I try to make the beginning accessible to everyone but then by the end I'm covering technical details and esoteric use cases that experts get held up on.
Like 4th year (non-full time) working on Python and this channel consistently keeps me feel stupid. I don't even get how you can call "send" method on a function... I wonder how many years author develops software to know these intricacies of language. And 42 reference was observed and appreciated, btw.
What's confusing here is that in the first example you have to use next() to get the next yield value but in the loop the next() is inferred. To me, that just destroys readability as the syntax has changed for no good reason.
dabeaz has written a bunch of really good stuff on generators. Maybe like 10 years ago? I think he gave some talks at PyCon back then, "build your own async" or something like that.
Please make an async video!! I would love it if you included best practices for incorporating async into sync func/programs I find most times i need something async i want to do sync stuff too or dont know how to convert it all to async
I love the relatively monotone presentation, which helps clarity, with only a few incredibly well placed jokes sprinkled here and there. Keep it up!
Monotone? I hear many inflections.
I would be offended at the implication towards my accent if I were in the TH-camrs shoes. 😢
@@Holphana You’re right, I just didn’t choose my words carefully enough. What I mean is that the presentation is that of a factual text, instead of creating unnecessary clutter through adding emotion or emphasis like so many other TH-camrs do.
Indeed, these are vastly the best videos on coding I've found.
What's really missing is a title card with a photo of M with chin in hands looking puzzle, or head-in-hands despairing at some topic that was exhorted in many keynote talks - TDD, say
What a wholesome reply :) @@biffenb7534
No matter how experienced you are, in your videos there is always a new small detail you didn't know about. Love it!
yes! I thought "oh. I know everything about yielding.."
and then.. bi-directional?! 🤯
Mate, I have years of Python experience, yet everytime you release a video I am floored by some of the stuff you showcase and I feel like I'm learning about the language for the first time. Stellar job, as always, and your presentation style is excellent for the job.
same
it's a little bit overwhelming lol
“Even if a file is gigabytes large you’ll only need enough memory to handle a single line” great point!
I swear every time I start watching a video on this channel I think “ah here is another thing I already know in python I probably won’t learn anything new this topic is pretty straight forward” and I end the video feeling like I never knew anything about it to begin with 😂😂 keep up the great work
Async (vs threading vs "other kinda-multitasking methods") video would be greatly appreciated. It's not the most useful stuff for your average script or simple program, so I rarely see good explanations of it for any language.
Always struggled with generators. Thanks for the amazing explanation!
Dude, you are a genius. I wonder why your vids aren't getting more views than those other millions of python hacks out there. Keep up the good work.
Your async explanation would be much appreciated! :)
I write things like "sum(x for x in range(10))" very often and I didn't know that was generator comprehension! I was thinking it was the same as writing "sum([x for x in range(10)])" (with brackets). Thanks a lot for your content!
Me too!
Why using a comprehension at all? Can't we just do sum(range(10)) ?
@@enkryp i was just about to mention! yeah range is directly iterable
That’s the difference between an “iterator” and an “iterable”. An “iterable” has an ‗‗iter‗‗ method, which returns an iterator when it is called. The iterator is what returns the elements of the sequence, until it is exhausted and can’t be called again.
Because range() is an iterable, you can reuse a single range object to return any number of iterators over that range.
@@lawrencedoliveiro9104 Yeah, your explanation helps me a lot.
Very insightful video! One other place I've seen generators used frequently is for API pagination. If, for instance, if you want to get all 100 records from an API, and the API limits your query to 10 records per call, you may not want to wait for all 10 calls. Instead you create a generator that calls the API only when you've completed working with the first page and are ready to move onto the second, etc.
Database queries is a good example. A very common sequence is
* Create a cursor object
* Execute a query on the cursor
* Iterate over the results returned from the cursor
* Close the cursor.
You can wrap all these steps up in a single generator function, which takes the query and lets you iterate over the results in a single step.
Thank you! By learning this I was able to create a toy version of the async coroutines, helped me a lot to grasp the concept of event loops
Outstanding video as always.
itertools might have deserved a mention since it is very useful with generators.
The jump from iterator to coroutine was a bit steep and I would personally love an async video
This is why I like your channel: Even when I think I know a topic well, I still expect to find something new in your videos, and I always do. Keep it up!
Yep, definitely interested in an async video. Especially interested in learning the "python native" async features and components so as to detangle it from all the third-party contributed stuff.
Just as I was about to suggest a video on async, James announced it himself. 👍🏻
Can't wait to see this convoluted topic explained in mCoding simple comprehensible manner.
Great video. It was eye opening for me when I learnt about generator comprehension. I realised that I was doing something very inefficient passing list comprehensions to sum and other functions.
Also worker example is amazing. Never used it this way.
Watched this video because I'm like, "I know what generators are, but I bet I'll learn something new about them." Found out that yield is an expression. Mind blown. Not disappointed.
Please make the async video.
yield became an expression in Python 2.5.
I would def like a video going deeper into "yield from" generator uses, with examples
Thank you for another great video.
I’ve been using generators for years, and still didn’t know some of this.
Finally something about generators. Never quite got them
"Where the only limit, is your imagination... and your download speed" - LOL I lost it here
craving for the async vid 🤤
Thank you so much for this video, and all of others. I've started reading Fluent Python a couple months ago, but that was quite hard for me to go through it. And you on your channel describe those hard for me things and I finally get them somehow. Thought I was dumb, but all i needed was to find a great lecturer. Thank you so much!
literally just had to learn about generators 2 days ago for a proj. the video timing is immaculate
I probably only got 20% of this video. But it was enough for me to fiddle around and learn more about generators' daily use cases to improve my performance...
Great video, Mcoding 😄
Every coding courses of yours it like math classes where you start at 1+1 and a simple zone out and suddenly you're on advanced mathematics.
Your videos are going into great depth mate! Im awaiting for that async vid of yours
You can pass things into a generator? Wow, incredible video!
"Thank you, next" was a nice touch.
That generator pipeline was eye-opening! I've worked with generators plenty, but still this pipeline idea escaped me
I think this will really help me with lazy execution via generators. This would have really helped if . Also, 'yield from' was hard for me to get from just the docs, so thanks for summing that up tidily.
always love the videos - would love an async video! Always learn a little tidbit from these
when i started python, i was so proud of my prime number generator function
when I feel on top of the world with my python knowledge, I go here to restore humility :D
Didn't know about generator chaining, that sounded very useful! Thanks
Made me realize how much I still need to learn. Great video!
didn't know about the generator pipeline and was blown away by it. big hype for the async video!
I was just told that list comprehension where faster than for loops... now it makes sense.
This video is definitely eye-opening. I thought that generators were just regular functions that you could re-enter, but I never comprehended how python calls them totally differently. Adding something like "if False: yield" to a regular function totally changes how it is called, despite those 2 lines of code being a noop.
Wow I thought I know almost everything about generators, but i was wrong! Well done!
There's always more to learn!
Same.
I watched quite few videos about async but I would still like your take as well. It is one of the more complicated/complex? parts of the language to grasp.
Very nice CTA at the end, hadn't noticed it before, clever :)
Otherwise great video and can't wait to know how async uses generators, I've been curious about that ever since you mentioned it a while ago.
not just imagination or/and downloadspeed but also your pride deciding what you appropriate from the interwebs or what you painstakingly program yourself in most likely a less efficient methode.
ALL hail @mcoding High Priest of the Python temple!! Your explanations are succinct, and the usage examples help me so much to grasp the concepts. Thank you.
Thank you ! And yes for the async video
You cannot see this (hopefully) but I had to give a standing ovation to this one.
I saw it!
@@mCoding 😱😱😱😱😱😱😱
I really appreciate your videos. I always learn something new, even when I don't think I will. TIL parenthesis make generator comprehension. :)
Nice work! I cannot wait to start using these generator techniques!
Thank you for this! Excellent deep dives. Your videos are a great source for understanding the why/how behind functionality.
Plot twist: The 1 Gb file you're trying to read, has only 1 line xD
Awesome video. The send method confuses me a lot every time I see it, I don't know why lol
I am a fan of generators. I use "yield from" when the function that generates the next thing happens to be recursive. For example, I have a generator that takes a list of N things, and yields each permutation of those N things, and the underlying algorithm is recursive.
It’s crazy, being able to tell how intelligent another human is just behind a screen/video.
Thank you so much. This was a very confusing topic.
Super informative video, thank you, very interesting
@9:08 It's crazy that you can even have the same name for the generator comprehensions, so all of them called "nums".
No, I don’t want a video on asyncio. I want a whole goddamn *series.*
Take note of how I'm methodically making videos on all the prerequisites for a deep async discussion 🙃
@@mCoding can't wait, i am facing some issue in one of my projects and understanding how asyncio works inside out would be very helpfull
I have imagination...I just lack drive, passion, purpose, stamina, motivation, IQ, and I essentially am unable understand social ques...
Good stuff, I didn't know most of the advanced stuff here.
Thanks! I always learn something new and really impressive watching your videos. Wish you twice as much subs
> "Do you think, they would really introduce a whole new set of keywords just to have a shortened for-loop?"
Yes. The answer is "Yes, I can see the Python devs do that."
I'm really liking your videos! I would love to see an async video from you!
Looking forward to the async video 👍🥳
Looking forward to the asyncio video!
Great video as always! And would love to see a video on async
Thumbs up.
4:27 This might be a rather be a problem of spell-checking settings than on syntax.
I can't wait for the async video!
looking forward for async video, great job
Man you killed it with the Ariana Grande 😂😂
Can you do a video on making __iter__ a generator vs defining a __next__? I’ve seen both in the wild, you seem preferential to the __iter__ generator, and I’ve googled to no avail. I’m mostly interested in which one is more pythonic, but I’d also like to know what you think the use cases for each are. Great videos!
4:25 - Pycharm thinks your text file is a requirement.txt.
Now if only I was doing something complex enough to merit this new found tool in my python bag... One day
I enjoy your dives under the hood of stuff I routinely use and thought I knew well.
It might be worth pointing out that generator comprehensions can have closures like functions can:
def multiples(value):
return (value * x for x in [1, 2, 3])
fives = multiples(5)
for number in fives: # 5 is now embedded in fives
print(number)
TH-cam comments need code formatting markup. At least on this channel.
So useful, even yhough i don't understand the last half of the video. Maybe one day i will😅
Helped me refactor some code and provide some memory savings! Thank you!
4:44 what is this _make method you call? I wasn't expecting this code to run, but it still did, even though it doesn't appear you defined the method? Is this something generated by dataclass?
Note that MyDataPoint class is the type NamedTuple. I googled for "_make NamedTuple Python" and got some info on the function. Turns out that _make is part of the NamedTuple class.
Also note that's its a NamedTuple and not a data class. This just means that you have different functions that you can use. So no comparison, like you do with data classes. You CAN do it, but you'll have to implement it yourself.
@@NostraDavid2 I see, thanks for pointing it out. So, I'm not sure why I thought it was a dataclass, but I guess I just saw the type annotations and didn't read the top part. That makes a lott more sense, big thanks :)
Do you think it would be a good idea for the else clause in the for/in/else loop to be the place where the generator's returned value is made available?
"Did you really think they would add a new keyword just to abbreviate a for loop?"
This is python so yes, yes I did
Look forward to an async video
Really advanced high value stuff! Thanks!
Great videos pall. Please make that async video.
In collatz generator checking for n == 1 should be at the top otherwise it behaves funny with input of 1: [4, 2, 1] :)
Good catch! Yes you are absolutely right.
Let’s go Patronssss
It's like a clockwork function. Every time it's called the cog moves a tick.
I would enjoy a video about asyncio a lot
I am async awaiting for the video on async!
9:40 - is there a nicer way to chain the generators like this? To not repeat the "nums" etc?
Hooray for Python and yield from. Because the code smelled like it wanted to do that and Python does it. I only know C#, which has "generators", and yielding "from" is an obvious thing one would want to do.
Start of video: Ah yes, this is a cool useful Python feature that I didn't know about!
End of video: What is even going on
Haha welcome to my channel! A lot of my videos are guilty of this. I try to make the beginning accessible to everyone but then by the end I'm covering technical details and esoteric use cases that experts get held up on.
@@mCoding no problem man, it's nice that anyone at any skill level can learn something from these videos
Like 4th year (non-full time) working on Python and this channel consistently keeps me feel stupid. I don't even get how you can call "send" method on a function... I wonder how many years author develops software to know these intricacies of language.
And 42 reference was observed and appreciated, btw.
Yes please on the async. It's a confusing feature for me
I've been using generators for years. I had no idea yield was bidirectional!
What's confusing here is that in the first example you have to use next() to get the next yield value but in the loop the next() is inferred. To me, that just destroys readability as the syntax has changed for no good reason.
Vote for asyncio video! That would be really awesome!
Thank you. Amazing explanation.
damn i need to watch this video over and over again :D. Love it!
I like the Ariana Grande part…..😂
dabeaz has written a bunch of really good stuff on generators. Maybe like 10 years ago? I think he gave some talks at PyCon back then, "build your own async" or something like that.
Please make an async video!! I would love it if you included best practices for incorporating async into sync func/programs
I find most times i need something async i want to do sync stuff too or dont know how to convert it all to async
Super Content. Thanks for sharing with us 🥰🥰