Created
February 2, 2012 03:32
-
-
Save built/1721251 to your computer and use it in GitHub Desktop.
Python's Nested List Comprehensions
This file contains hidden or 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
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()] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.