Where is the usage of (list comprehension) documented?
Peng Yu
pengyu.ut at gmail.com
Sun Jan 14 18:01:43 EST 2018
Hi,
I see the following usage of list comprehension can generate a
generator. Does anybody know where this is documented? Thanks.
$ cat main.py
#!/usr/bin/env python
import sys
lines = (line.rstrip('\n') for line in sys.stdin)
print lines
lines = [line.rstrip('\n') for line in sys.stdin]
print lines
$ seq 10 | ./main.py
<generator object <genexpr> at 0x1101ecd70>
['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']
--
Regards,
Peng
More information about the Python-list
mailing list