Skip to content

Instantly share code, notes, and snippets.

@rolandcrosby
Last active April 16, 2020 21:40
Show Gist options
  • Save rolandcrosby/0d840e04162d943b54e3dd726413f8f6 to your computer and use it in GitHub Desktop.
Save rolandcrosby/0d840e04162d943b54e3dd726413f8f6 to your computer and use it in GitHub Desktop.

these are all pretty similar --

Scala:

val outer = List(List(1, 2, 3, 4, 5), List(4, 5, 6, 7, 8))
for {
  inner <- outer
  x <- inner
} yield x

Python:

outer = [[1, 2, 3, 4, 5], [4, 5, 6, 7, 8]]
[x for inner in outer for x in inner]

Haskell:

outer = [[1, 2, 3, 4, 5], [4, 5, 6, 7, 8]]
[x | inner <- outer, x <- inner]

-- so why does python's syntax feel so uniquely backwards to me?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment