Last active
September 22, 2024 16:24
-
-
Save telekosmos/c5b170c1a66e8522e3f995587baaa9cf to your computer and use it in GitHub Desktop.
Nested list comprehension
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
# also a comprehension version of flatten | |
matrix = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] | |
condition = lamda x: x % 2 != 0 | |
odd_numbers = [element for row in matrix for element in row if condition(element)] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment