You're NOT Managing Your Memory Properly | Python Generators (Yield)

preview_player
Показать описание
How using Python generators (aka the yield statement) can be advantageous to program design and memory efficiency and management.

0:00 - Introduction
0:25 - Lists
2:51 - Generators
5:47 - Rolling Returns
8:00 - Outro
Рекомендации по теме
Комментарии
Автор

Wow. I was just studying generators, but was finding it slightly difficult and unnecessary. Now I understand it's importance. Thank you for this video 🙏🏼

adityashukla
Автор

1:59 the graph here actually confuses the viewer: in the first example memory consumption of the whole loop grows quadratically and in the second it grows linearly (like the graph shows for the first one). sys.getsizeof returns linearly growing size because list type stores only references to its values, but the strings themselves also grow linearly, which gives an overall consumption of O(n^2) in the first case

areniyan
Автор

New subscriber, like your content, REALLY like that you just jump right into it. I think creators sometimes forget that minutes wasted really add up over time, thank you for wasting no time!

CaseyFahey
Автор

This is one of the cleanest edited videos I've seen, and great info

domenicfieldhouse
Автор

And if for some reason you want to see all of the content to be generated, you can just cast it to a list e.g. list(your_generator) or [*your_generator]

re.liable
Автор

Excellent clear and conscise. Looking forward to more content!

williamrich
Автор

Love the video, @DanielBoctor. Would love to see videos on advanced Django!

abhishekchoudhury
Автор

Your videos make me want to learn Python all over again 😮 amazing video!

TheControlMastr
Автор

Very practical insights, thanks a lot for this

Darkev
Автор

Okay, so basically, don't process or generate data before you really need to. Good message, just needs some more real world examples.

anon_y_mousse
Автор

Ery informative video... What are your thoughts about using it when using to
(i) receive api get requests followed by a loop on the response data
(ii) to sort the data without using it in any loop?

darshanrajpattanaik
Автор

Is there an equivalent to Generators in Cobol-72?

Only joking.

Compilers are wonderful things. Their enrichment of capabilities are opening up opportunities beyond our wildest dreams.

Simple_Simon_UK
Автор

I almost always use yield generators ! Mostly because it's faster lazyier processing, for better speed performance, and or asynchronousity manipulation. But it's wonderful to see such a clear example of how this is also memory efficient and a must for big data processing.

Thanks for the regular bracket trick! (ftw) didnt know about that! Love this channel! Love python! Subscribed! All the best

fire
Автор

In case of list comprehension vs generator, most of the time list comprehension is much faster. If you don't have memory issue and have constant size elements, the speed is worth it.

So in rolling returns, it is fine to use lists for windows and it would be much faster.

tunafllsh
Автор

it seems like you're using the word "residual" to mean "minuscule".

Given that "residual" means "remaining after the greater part or quantity has gone.", I'm not quite clear what greater part of the function's memory you'd be referring to.

john.dough.
Автор

Pretty funny how your generator can be using a other generator

seasong