This is a code in a book.
import csv
villains = [['Doctor', 'No'],
['Rosa', 'Klebb'],
['Mister', 'Big'],
['Auric', 'Goldfinger'],
['Ernst', 'Blofeld'],
]
with open('villains', 'wt') as fout:
csvout = csv.writer(fout)
csvout.writerows(villains)
with open('villains', 'rt') as fin:
cin = csv.reader(fin)
villains = [row for row in cin]
print(villains)
My result is
[['Doctor', 'No'], [],
['Rosa', 'Klebb'], [],
['Mister', 'Big'], [],
['Auric', 'Goldfinger'], [],
['Ernst', 'Blofeld'], []]
Expected result is
[['Doctor', 'No'],
['Rosa', 'Klebb'],
['Mister', 'Big',
['Auric', 'Goldfinger'],
['Ernst', 'Blofeld']]
But I have some empty list in my result. I don't understand why these are appearing.
MY QUESTION
What in my code makes the empty lists?
How to correct my code to obtain expected result?
Thanks in advance.