• Re: The joy of Python

    From p.dean@p.dean@invalid.net (Peter Dean) to alt.folklore.computers,comp.lang.rexx on Thu Oct 10 04:39:02 2024
    From Newsgroup: comp.lang.rexx

    In alt.folklore.computers lar3ryca <larry@invalid.ca> wrote:
    On 2024-10-09 02:27, Kerr-Mudd, John wrote:
    On Wed, 9 Oct 2024 07:12:49 -0000 (UTC)
    p.dean@invalid.net (Peter Dean) wrote:

    In alt.folklore.computers Lawrence D'Oliveiro <ldo@nz.invalid> wrote:
    On Tue, 8 Oct 2024 19:53:39 -0600, lar3ryca wrote:

    #!/usr/bin/rexx
    /* Show only one copy of each line in a whole file */
    seen. = 0
    Do While Lines() > 0
    Parse Pull this_line
    If seen.this_line Then Iterate
    seen.this_line = 1
    Say this_line
    end

    #!/usr/bin/python3
    # Show only one copy of each line in a whole file
    import sys
    seen = set()
    for line in sys.stdin :
    if not line in seen :
    sys.stdout.write(line)
    seen.add(line)

    #!/usr/bin/perl
    my %seen;
    while (<>) {
    if (!$seen{$_}) {
    $seen{$_}++;
    print;
    }
    }


    Perl wins! -much more obscu^w shorter

    Good to know that other languages can do it, even if _I_ can't wrap my
    head around them.

    and that was just a direct translation. This is more idiomatic perl.

    #!/usr/bin/perl
    while (<>) {
    print unless $seen{$_}++;
    }

    --- Synchronet 3.21a-Linux NewsLink 1.2