Skip to content

Instantly share code, notes, and snippets.

@built
Created February 2, 2012 03:32
Show Gist options
  • Save built/1721251 to your computer and use it in GitHub Desktop.
Save built/1721251 to your computer and use it in GitHub Desktop.
Python's Nested List Comprehensions
words = []
for line in sys.stdin.readlines():
for word in line.split():
words.append(word)
# VS.
words = [word for line in sys.stdin.readlines() for word in line.split()]
@built
Copy link
Author

built commented Feb 2, 2012

Here's how I'd like it to be:
[word for word in line.split() for line in sys.stdin.readlines()]

Or at least how I expect it to be.

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