Python 101 : Generators and Lists


A list is a collection of values stored in memory.

A generator does not build a list, it only tells us how to generate these values with nothing stored in memory.


Our examples below use the "range()" iterator and they produce the same results.


Below is our list example:



And our generator example:



The generator expression generate values only when they are needed which saves us system resources, especially with huge amounts of data.

Comments

Popular posts from this blog

Istio 101 : How Istio ServiceEntry relates to Kubernetes Services and Endpoints

Kubernetes 101 : - Scaling a Stateful set -