I am currently creating a list from an input file like this:
list = inputFile.read().splitlines()
Then after that manually iterating through and making a second list of the items/lines I care about (which are lines 2,6,10,14,18...). Is there a faster way to do this just with splitlines() so automatically, list contains only the lines I care about?
itertools.islice(iterable, start, stop[, step]) is the tool for the job:
from itertools import islice
for line in islice(inputFile, 2, None, 4):
print line
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With