Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eder-projetos-dev/2c167f73eed5b1ffd2476ef028c3f8a1 to your computer and use it in GitHub Desktop.
Save eder-projetos-dev/2c167f73eed5b1ffd2476ef028c3f8a1 to your computer and use it in GitHub Desktop.
Python - Generator expressions
squares = (num**2 for num in range(1, 11))
@eder-projetos-dev
Copy link
Author

eder-projetos-dev commented Jun 3, 2023

Generator Expressions

I like generator expressions when I’m dealing with large datasets and memory efficiency is crucial. Rather than creating a list of all squared numbers, a generator expression creates an iterator that generates each squared number on-the-fly. This saves memory and allows for efficient processing of large datasets.

https://levelup.gitconnected.com/11-tricks-that-will-make-your-life-easier-as-a-python-developer-da29e4306675

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment