import csv
with open(\'thefile.csv\', \'rb\') as f:
data = list(csv.reader(f))
import collections
counter = collections.defaultdict(int)
for row in data:
When using Python 3 the empty lines can be avoid by using the codecs module. As stated in the documentation, files are opened in binary mode so no change of the newline kwarg is necessary. I was running into the same issue recently and that worked for me:
with codecs.open( csv_file, mode='w', encoding='utf-8') as out_csv:
csv_out_file = csv.DictWriter(out_csv)