Skip to content

Instantly share code, notes, and snippets.

@telekosmos
Last active September 22, 2024 16:24
Show Gist options
  • Save telekosmos/c5b170c1a66e8522e3f995587baaa9cf to your computer and use it in GitHub Desktop.
Save telekosmos/c5b170c1a66e8522e3f995587baaa9cf to your computer and use it in GitHub Desktop.
Nested list comprehension
# 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