Python reads lines from a file with the trailing newline included, and line.split(",") with only one column (i. e. no comma) keeps the whole line. As you already know about the csv module you should use it to read your data, e. g. instead of
> A = [line.split(',')[0] for line in open('Afile.csv')]
try
with open("Afile.csv", "rb") as f:
a = {row[0] for row in csv.reader(f)}
...
I used {...} instead of [...], so a is already a set and you can proceed:
in_a_not_b = a - b
Finally as a shortcut for
for item in in_a_not_b:
writer.writerow([item])
use the writerows() method to write your data:
with open("inAnotB.csv", "wb") as f:
writer = csv.writer(f)
writer.writerows([item] for item in_a_not_b)
Note that I'm wrapping every item in the set rather than the complete set as a whole. If you wanted to be clever you could spell that even more succinct as
writer.writerows(zip(in_a_not_b))