Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?

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
You can’t perform that action at this time.