Sala de Sinais

Python Tutorial: Generators – How to use them and the benefits you receive

* O link para o vídeo completo está no final desse artigo.
Saiba mais clicando em Robô IQ OPTION de AUTOMATIZAÇÃO de Lista de SINAIS
E conheça também sobre o Melhor Bot Para Opções Binárias 2021
Que tal um robo gratuito para IQ Option? Sistema Para IQ Option Grátis

Python Generators are often considered a somewhat advanced topic, but they are actually very easy to understand once you start using them on a regular basis. Actually, after you use generators for some time, you will often find them more readable and performant than other options.

In this video, we will look at what a python generator is, how and why we would use one, and the performance benefits they give us.

The code from this video can be found at:

✅ Support My Channel Through Patreon:

✅ Become a Channel Member:

✅ One-Time Contribution Through PayPal:

✅ Cryptocurrency Donations:
Bitcoin Wallet – 3MPH8oY2EAgbLVy7RBMinwcBntggi7qeG3
Ethereum Wallet – 0x151649418616068fB46C3598083817101d3bCD33
Litecoin Wallet – MPvEBY5fxGkmPQgocfJbxP6EmTo5UUXMot

✅ Corey’s Public Amazon Wishlist

✅ Equipment I Use and Books I Recommend:

▶️ You Can Find Me On:
My Website –
My Second Channel –
Facebook –
Twitter –
Instagram –



36 Comentários

  1. this was extremely usefull for webscraping as well. so the prgm i made initially would scrape through the site and store all the results in a list and only after getting all the results and returning it i would be able to display it all at once. and as you could imagine this takes a lot of time but with this , i could easily display each result just as the prgm finds it. so thks a lot

  2. If a generator object outperforms a list and has additional functionality, is there really ever a reason to just use a list?

  3. awesome dude….. short and complete. u made it super simple. u just got a subscriber.

  4. Comparing times in not really that fair though because the generator is not actually doing anything. If we were to loop over people the generator would take slightly longer because it has to call random.choice a bunch of times. Then, of course, in this particular example it would win anyway in the overall timing because in the list we would be looping for a second time.

  5. Is there a way to jump to a specific iteration or index when using a generator? Like if you wanted to get the 100th generated person, but didn't want to loop through the first 99.

    Amazing video by the way, very informative.

  6. This is probably the best way to process data when you want to simply manipulate it from a database and back in, right?

  7. This is nice for big data, but for me I don't think so or could you access element i directly?

  8. “I think it’s a bit more readable,” still uses .format lol
    Good video, though!

  9. This is a great explanation of how to create a generator and why you might want to use one. However, while there is a computational performance improvement with generators, it might not always be quite as good an improvement as this example shows. That's because in the person generator example here, the generator is never used once it is created.

    A better comparison would be to iterate over the person generator (or call on it in a loop) so that the same number of person objects are created in both examples. It should still be faster than the list example because copying data into the list takes time, and memory pressure will force the OS to allocate more memory to the process as the list grows, requiring even more copying each time the list is resized.

  10. in the early example, if you are using the array literal in the generator function anyways, you are not saving the memory. but instead if you are just using an i and doing i++, it will indeed do the trick. So, implementation in the generator matters!

  11. Awesome video! I really appreciate that I not only know how to use generators now, but also have some ideas for use-cases because of the advantages you explained.

  12. is it possible to quickly ask the generator to process say the "200th element" of a generator object and retrieve the result? or do I have to request a value from the generator 200 times in a loop?

  13. oDEAR a ONION-check? listenONaAUTOcompleteVISUALdesignerGUI it's 2021 MR.SPOK wait for a MIT puzzle TOOL to listen DEBUGvar`s in REALtime or? MR. ENTERprice what`s a OO or what`s a 00 . thx oe5RDS 77.5Khz [({now with a ³²1 UNICODE KEYboard 😉

  14. I've been searching for reliable sources to learn python. I came across Corey Schafer and never left since then. Corey schafer stan

  15. Advantages of generator:
    1. readable
    2. boost performance (execution time, memory)
    3. don't lose advantage of list comprehension (change bracket to paranthesis)

  16. hi Corey, everything is fine but at last, I got an error "ModuleNotFoundError: No module named 'mem_profile'", I got this while I using
    "import mem_profile" … I would appreciate it if you help me regarding this.

  17. Hey Corey Can you please explain me physics and chemistry? Looks like you are the only one who can explain me the things.

  18. If you are reading data from a file, each read of that data takes time. Same with querying a database.
    For a million rows of data, wouldn't it be faster to read them all into memory before doing the computations rather than reading them line by line?
    Or would you use a generator to say, read 20,000 lines at a time?

  19. I never knew I needed Matthew McConaughey to teach me how to use generator objects but I did. Thanks pal, great vid.

  20. In your final example it took 1.2 seconds with the list function and basically 0 time with the generator. Wouldn't your program still have to spend 1.2 seconds later on as you are calling on the generator?–each item taking 1.2s/1,000,000? If you actually need all the values, it would save memory but not time unless I'm missing something.

Comentários estão fechados.