Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.lisp > #60253

Re: ( Substring function in Python, Lisp) -- [Hijack] contains [hijk]

From Paul Rubin <no.email@nospam.invalid>
Newsgroups comp.lang.lisp
Subject Re: ( Substring function in Python, Lisp) -- [Hijack] contains [hijk]
Date 2025-02-16 23:44 -0800
Organization A noiseless patient Spider
Message-ID <878qq5582x.fsf@nightsong.com> (permalink)
References (1 earlier) <m3o6z2wvuh.fsf@leonis4.robolove.meer.net> <874j0ucpn1.fsf@nightsong.com> <m3r03xvqsn.fsf@leonis4.robolove.meer.net> <87bjv1vaos.fsf@nightsong.com> <m3v7t95aie.fsf@leonis4.robolove.meer.net>

Show all headers | View raw


Madhu <enometh@meer.net> writes:
> FWIW My code is pretty clunky, somehow TIME SBCL says it conses 0 bytes
> when I run it on individual words without interning although when I'm
> explicitly manipulating plists and arrays.

Yikes.  I did a Python version that conses a lot but is fairly concise,
I thought.  From the looks of things, your /usr/share/dict/words is
larger than mine.  Mine has about 100k entries and this code took about
0.7 seconds on my laptop, not great, but obviously many optimizations
are possible with the same basic approach:

    from collections import defaultdict

    def runlen(word:str) -> int:
        d = defaultdict(int)
        def pred(c): return chr(ord(c)-1) # unicode predecessor
        for c in word:
            d[c] = d[pred(c)] + 1
        return max((n,c) for c,n in d.items())

    def main():
        for w in open('/usr/share/dict/words'):
            n,c = runlen(w.strip())
            if n>=5: print(w.strip(),n,c)

    main()

Back to comp.lang.lisp | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

( Substring function in Python, Lisp)  --  [Hijack]  contains  [hijk] HenHanna <HenHanna@dev.null> - 2025-02-15 21:36 +0000
  Re: ( Substring function in Python, Lisp)  --  [Hijack]  contains  [hijk] Lawrence D'Oliveiro <ldo@nz.invalid> - 2025-02-15 23:56 +0000
  Re: ( Substring function in Python, Lisp)  --  [Hijack]  contains  [hijk] richard@cogsci.ed.ac.uk (Richard Tobin) - 2025-02-16 00:18 +0000
    Re: ( Substring function in Python, Lisp)  --  [Hijack]  contains  [hijk] Paul Rubin <no.email@nospam.invalid> - 2025-02-15 23:43 -0800
      Re: ( Substring function in Python, Lisp)  --  [Hijack]  contains  [hijk] HenHanna <HenHanna@dev.null> - 2025-02-16 13:37 +0000
      Re: ( Substring function in Python, Lisp)  --  [Hijack]  contains  [hijk] richard@cogsci.ed.ac.uk (Richard Tobin) - 2025-02-16 19:02 +0000
  Re: ( Substring function in Python, Lisp)  --  [Hijack]  contains  [hijk] Madhu <enometh@meer.net> - 2025-02-16 06:26 +0530
    Re: ( Substring function in Python, Lisp)  --  [Hijack]  contains  [hijk] Paul Rubin <no.email@nospam.invalid> - 2025-02-15 23:30 -0800
      Re: ( Substring function in Python, Lisp)  --  [Hijack]  contains  [hijk] Paul Rubin <no.email@nospam.invalid> - 2025-02-15 23:38 -0800
      Re: ( Substring function in Python, Lisp)  --  [Hijack]  contains  [hijk] Madhu <enometh@meer.net> - 2025-02-16 21:13 +0530
        Re: ( Substring function in Python, Lisp)  --  [Hijack]  contains  [hijk] HenHanna <HenHanna@dev.null> - 2025-02-16 18:33 +0000
          Re: ( Substring function in Python, Lisp)  --  [Hijack]  contains  [hijk] Madhu <enometh@meer.net> - 2025-02-17 12:39 +0530
            Re: ( Substring function in Python, Lisp)  --  [Hijack]  contains  [hijk] HenHanna <HenHanna@dev.null> - 2025-02-17 11:50 +0000
        Re: ( Substring function in Python, Lisp)  --  [Hijack]  contains  [hijk] Paul Rubin <no.email@nospam.invalid> - 2025-02-16 13:31 -0800
          Re: ( Substring function in Python, Lisp)  --  [Hijack]  contains  [hijk] Madhu <enometh@meer.net> - 2025-02-17 12:21 +0530
            Re: ( Substring function in Python, Lisp)  --  [Hijack]  contains  [hijk] Paul Rubin <no.email@nospam.invalid> - 2025-02-16 23:44 -0800
  Re: ( Substring function in Python, Lisp) -- [Hijack] contains [hijk] "Carl G." <carlgnews@microprizes.com> - 2025-02-16 11:44 -0800
  Re: ( Substring function in Python, Lisp) -- [Hijack] contains [hijk] "B. Pym" <Nobody447095@here-nor-there.org> - 2025-06-06 15:17 +0000

csiph-web