Created
June 3, 2023 17:06
-
-
Save eder-projetos-dev/521c78e6e295eb6a7a636c14c09bb443 to your computer and use it in GitHub Desktop.
Python - Set comprehensions
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
even_numbers = {num for num in range(1, 11) if num % 2 == 0} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Set Comprehensions
I find set comprehensions useful when I need to create a set containing unique elements based on some condition. For example, if I want to create a set of even numbers from 1 to 10, I can use a set comprehension along with a conditional statement to filter out the odd numbers.
https://levelup.gitconnected.com/11-tricks-that-will-make-your-life-easier-as-a-python-developer-da29e4306675