Created
June 3, 2023 17:08
-
-
Save eder-projetos-dev/2c167f73eed5b1ffd2476ef028c3f8a1 to your computer and use it in GitHub Desktop.
Python - Generator expressions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
squares = (num**2 for num in range(1, 11)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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