I am trying to delete blank lines from text file. Following is my take on it
aa=range(1,10)
aa[3]=""
print aa
[1, 2, 3, '', 5, 6, 7, 8, 9]
for i in range(0,len(aa)):
if aa[i]=="":
del aa[i]
print lines
[1, 2, 3, 5, 6, 7, 8, 9]
Now I am trying to replicate same methodology on the text file to delete a blank line but it is not working.
f=open("sample.txt",'r')
lines=[]
for i in f:
lines.append(i)
print lines
['In this 30th match\n', '\n', 'there will be no1 winner']
for i in range(0,len(lines)):
if lines[i]=="":
del lines[i]
print lines
['In this 30th match\n', '\n', 'there will be no1 winner']