Generator Expressions

Learn about the generator expressions with the help of an example.

We'll cover the following

Overview

Sometimes we want to process a new sequence without pulling a new list, set, or dictionary into system memory. If we’re iterating over items one at a time, and don’t actually care about having a complete container (such as a list or dictionary) created, a container is a waste of memory. When processing one item at a time, we only need the current object available in memory at any one moment. But when we create a container, all the objects have to be stored in that container before we start processing them.

Example

For example, consider a program that processes log files. A very simple log might contain information in this format:

Get hands-on with 1200+ tech skills courses.