On 17 February 2014 13:16, Dave Angel <da...@davea.name> wrote: > On 02/17/2014 06:12 AM, Oscar Benjamin wrote: >> >> Something like this: >> >> with open(r'D:\file3.txt', 'r+') as fout: >> keywords_seen = set() >> for filename in r'C:\File1.txt', r'C:\File2.txt': >> with open(filename) as fin: >> for line in fin: >> keyword = line.strip() >> if keyword not in keywords_seen: >> fout.write(line) >> keywords.add(keyword)
The line above should obviously be keywords_seen.add(keyword) > You forgot to append the newline to strings in the write() method calls. > > fout.write(line + "\n") Iterating over a file keeps the newlines: >>> list(open('file1.txt')) ['file1\n', 'file2\n'] Oscar _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor