General statistics
List of Youtube channels
Youtube commenter search
Distinguished comments
About
Anony Mousse
Indently
comments
Comments by "Anony Mousse" (@anon_y_mousse) on "What exactly is 'yield from' in Python? [Easy explanation]" video.
Basically it's lazy evaluation as someone else's function. You can get the same behavior in your own code if you write the loop yourself, it's just that sometimes you want to call it at different intervals and the lazy evaluation aspect means you might use less memory and not take an inordinate amount of time. To use an example from C, it's the difference between repeatedly calling strtok() to split a string and having a function that you write which creates an array of strings and splits it all in one go. I'm not as versed in Python and don't know if you can change inputs to a generator on the fly, but in C you can change the separators you pass to strtok() with any given call and it'll work correctly, whereas if you had an all in one function you'd either have to account for an array of multiple separator strings, or only get one set of separators. If that's not clear enough, then it might be worth it to ask @Indently to make a video explaining the implementation details of the generator construct, if he hasn't already, and he may have, I just haven't watched all of his videos.
2