How to select every other line from a text file?
Tim Chase
python.list at tim.thechases.com
Mon Oct 13 15:12:35 EDT 2014
On 2014-10-13 14:45, Joel Goldstick wrote:
> Not apropos to the OP, but what came up in my mind was to write a
> generator function that returns every other line. This would
> separate the reading from the writing code.
You mean like
offset = 0 # or 1 if you prefer
for line in itertools.islice(source_iter, offset, None, 2):
do_something(line)
?
-tkc
More information about the Python-list
mailing list