Last active
July 6, 2023 17:14
-
-
Save Integralist/1a256fc6e9112a084cddd94a49bb5fba to your computer and use it in GitHub Desktop.
Python if/else list comprehension (generator expression)
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
[i if i is True else 'nope' for i in [True, False, True]] | |
# [True, 'nope', True] | |
# Notice this is a conditional expression and different from list comprehension | |
# Which typically is `for ... if ...` | |
# Now it's reversed and no expression for truthy condition `if x <condition> else <expression>` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment