A Mountain of Perl Books + Python Advocacy
Fredrik Lundh
effbot at telia.com
Tue May 9 13:16:06 EDT 2000
tony summerfelt wrote:
> i think something like the following is pretty hard to beat:
/ line noise snipped ;-) /
> which is basically a 5 line simple uniq program.
and then he wrote:
> correct me if i'm wrong, but a duplicate of the last line is
> what's checked?
well, isn't that what a "uniq" program is supposed to do?
$ man uniq
...
DESCRIPTION
The uniq utility will read an input file comparing adjacent lines,
and write one copy of each input line on the output. The second
and succeeding copies of repeated adjacent input lines will not
be written.
Repeated lines in the input will not be detected if they are not
adjacent.
...
we cannot read perl, and we cannot read your mind...
but I can try (reading your mind, that is). maybe this does what
you want?
import fileinput, sys
uniq = {}
for line in fileinput.input():
uniq[line] = None
uniq = uniq.keys()
uniq.sort()
sys.stdout.writelines(uniq)
</F>
<!-- (the eff-bot guide to) the standard python library:
http://www.pythonware.com/people/fredrik/librarybook.htm
-->
More information about the Python-list
mailing list