Sunday, December 13, 2015

Printing alternate lines using python

for i, line in enumerate(file('myfile.txt')):

   if i % 5 in (0, 1):
       print line

f = open('filename.txt', 'r')
for index, line in enumerate(f.readlines()):
    if index%5 <= 1:
       print(line)