Python's simplicity philosophy

Michael Geary Mike at DeleteThis.Geary.com
Sat Nov 22 13:32:58 EST 2003


Curt wrote:
> I haven't shifted goalposts, whatever that means.  You shifted the
> emphasis of my example by removing only one of the duplicates.
>
> I concede that "uniq" does something "meaningful" on unsorted
> input, if that input contains identical, successive lines.  I do not
> concede, however, that you may never be required to sort its
> input in order to arrive at that state, which is exactly what my
> demonstration "proved".
>
> If I've just shifted goalposts, well, you can all shoot me at dawn,
> if you feel it's a capital offense.  Don't worry, we'll give you the
> real bullet.

Curt...

It is unfortunate that both the program name and the one-line description of
uniq are misleading:

       uniq - remove duplicate lines from a sorted file

Well, yes: If a file is sorted, then uniq removes all duplicate lines, and
the resulting file contains only unique lines (thus the name 'uniq').

But the fact remains that what uniq actually does has nothing to do with
sorting. It removes consecutive duplicate lines. That's all.

If I flip a coin 100 times and record the results, will there be consecutive
"heads" or "tails"? Most likely. Is that file sorted? Of course not--it's
completely random. Will uniq remove the consecutive duplicates? Yes.

It's really that simple.

-Mike






More information about the Python-list mailing list