I have a text file to parse line by line using python. I read the file as below,
with open(filename) as f:
soup = bs(f.read(),"html.parser")
then I split all the lines of the text file into a list.
allLine = soup.text.split("\r\n")
Now I am iterating the list one by one such as below,
Method 1:
for line in allLine:
# my task
My questing is, I can do the same iterating without storing the data into list also as below,
Method 2:
for line in soup.text.split("\r\n")
# my task
My Questions is,
Method 1 allocating extra spaces for the list 'allLines
'. But Method 2 doesn't need extra space. But will it do the split for 'n
' lines?
Which method is efficient?