Writing intersection data to new CSV
<p>I have 2 CSV files which have a list of unique words. After I complete my intersection on them I get the results, but when I try to write it to a new file it creates a very large sized file of almost 155MB, when it should be well below 2MB.</p>

<p><strong>Code:</strong></p>

<pre><code>alist, blist = [], []

with open("SetA-unique.csv", "r") as fileA:
    reader = csv.reader(fileA, delimiter=',')
    for row in reader:
        alist += row

with open("SetB-unique.csv", "r") as fileB:
    reader = csv.reader(fileB, delimiter=',')
    for row in reader:
        blist += row

first_set = set(alist)
second_set = set(blist)

res = (first_set.intersection(second_set))

writer = csv.writer(open("SetA-SetB.csv", 'w'))

for row in res:
     writer.writerow(res)
</code></pre>

<p>You're <em>writing</em> the entire set <code>res</code> to the file on each iteration. You probably want to write the rows instead:</p>

<pre><code>for row in res:
    writer.writerow([row])
</code></pre>

python csv