[Tutor] Performing an union of two files containing keywords
Dave Angel
davea at davea.name
Mon Feb 17 11:59:33 CET 2014
Aaron Misquith <aaronmisquith at gmail.com> Wrote in message:
> As two others have said, a set is the simplest solution to avoid duplicates.
There are other questions to ask, however. Primary is whether
order matters.
If it does not, then observe that list(set(mylist)) will produce a
list from a list without duplicates.
If order does matter, then I ask whether there was some constraint
that forced you to do it 3 lines.
If not, I would suggest that you write the output one line at a
time, after checking each line against a set. If the line is not
in the set, add it to the set and write it to the file.
And watch out for newlines. What happens if one or both input
files are missing their final newlines?
--
DaveA
More information about the Tutor
mailing list