[Tutor] Performing an union of two files containing keywords
Mark Lawrence
breamoreboy at yahoo.co.uk
Mon Feb 17 10:42:44 CET 2014
On 17/02/2014 09:07, Aaron Misquith wrote:
> I have 2 different text files.
>
> File1.txt contains:
>
> |file
> RAM
> Python
> parser|
>
> File2.txt contains:
>
> |file
> 1234
> program|
>
> I want to perform an union of these both files such that i get an output
> file3.txt which contains:
>
> |file
> RAM
> Python
> parser
> 1234
> program
> |
> The program that i'm working on just combines two files. Any help on
> performing an union such that a keyword would not be repeated would be
> appreciated.
>
>
> Code:
> with open("C:\\File1.txt") as fin1: lines = fin1.readlines()
> with open("C:\\File2.txt") as fin2: lines.extend(fin2.readlines())
> with open("D:\\file3.txt", "r+") as fout: fout.write('\n'.join(lines))
>
Use sets http://docs.python.org/3/library/stdtypes.html#set
--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.
Mark Lawrence
---
This email is free from viruses and malware because avast! Antivirus protection is active.
http://www.avast.com
More information about the Tutor
mailing list