Have you ever had to write a method that takes an iterable container (list, set, etc) and have to perform operations over it to return another iterable container as output? If yes, then python generators might be the first optimization tool you should look into.

Image for post
Image for post

What are python generators?
Generators are iterators, but you can only iterate over them once. It’s because they do not store all the values in memory, they generate the values on the fly. You use them by iterating over them, either with a ‘for’ loop or by passing them to any function or construct that iterates. Most of the time generators are implemented as functions. …


Chetan Mishra

An enthusiastic learner

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store