help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Find the longest word in the word list file.


From: Hongyi Zhao
Subject: Re: Find the longest word in the word list file.
Date: Wed, 11 Aug 2021 22:17:02 +0800

On Wed, Aug 11, 2021 at 9:58 PM Stephen Berman <stephen.berman@gmx.net> wrote:
>
> On Wed, 11 Aug 2021 07:14:05 +0800 Hongyi Zhao <hongyi.zhao@gmail.com> wrote:
>
> > I have an English word list file that stores words in a
> > one-word-per-line format. Now I want to find the longest word in the
> > word list file. For example, I can use standard UNIX tools to
> > accomplish this with the following simple commands:
> >
> > $ awk '$0 ~ /^[[:alpha:]]+$/ { print $0, length($0) }'
> > american-english-exhaustive | \
> > sort -k2n | tail -1
> > Llanfairpwllgwyngyllgogerychwyrndrobwllllantysiliogogogoch 58
> >
> > But in Emacs, what is the elisp implementation for the above task?
>
> Here's another way.  Say e.g. the following is the buffer with your list
> of words:
>
> Theory
> and
> Simulation
> of
> Materials
>
> First do this:
>
> (setq l
> '(Theory
> and
> Simulation
> of
> Materials))
>
> Evaluate the preceding sexp, then evaluate the following sexp:
>
> (car (sort l (lambda (a b)
>                (> (length (symbol-name a)) (length (symbol-name b))))))

Good. A bubble sorting, IIRC.

> =>
> Simulation
>
> Steve Berman

Best, Hongyi



reply via email to

[Prev in Thread] Current Thread [Next in Thread]