Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #107436
| Path | csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail |
|---|---|
| From | Chris Angelico <rosuav@gmail.com> |
| Newsgroups | comp.lang.python |
| Subject | Re: Detecting repeated subsequences of identical items |
| Date | Thu, 21 Apr 2016 15:37:38 +1000 |
| Lines | 37 |
| Message-ID | <mailman.2.1461217068.23626.python-list@python.org> (permalink) |
| References | <571843f9$0$1585$c3e8da3$5496439d@news.astraweb.com> <CAPTjJmoM7hypFBXWM_PkCHmv1usUq91pst6D+uwFTgejTpPaJw@mail.gmail.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=UTF-8 |
| X-Trace | news.uni-berlin.de CQ1h0L7BA8+TuT2IVO59MwwCdRPgdeVyue7Ue5wdFn1Q== |
| Return-Path | <rosuav@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.003 |
| X-Spam-Evidence | '*H*': 0.99; '*S*': 0.00; 'received:209.85.223': 0.03; '21,': 0.07; 'purpose.': 0.07; 'cc:addr:python-list': 0.09; 'thu,': 0.15; '*almost*': 0.16; '2016': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'grouped': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'subject:Detecting': 0.16; 'wrote:': 0.16; 'have:': 0.18; '>>>': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'txt': 0.22; 'split': 0.23; 'header :In-Reply-To:1': 0.24; "i've": 0.25; 'skip:" 20': 0.26; 'message- id:@mail.gmail.com': 0.27; 'work.': 0.30; "can't": 0.32; "d'aprano": 0.33; 'steven': 0.33; 'received:google.com': 0.35; 'done': 0.35; 'quite': 0.35; 'but': 0.36; 'received:209.85': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'two': 0.37; 'no,': 0.38; 'received:209': 0.38; 'chrisa': 0.84; 'or:': 0.84; 'to:none': 0.91; 'abc': 0.91 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc; bh=Z8FBr+NpJ3EzSBdh9yMEUVf3c2QZ99iwkRBxlzEfoo4=; b=QGO/LrBJEqMtPLYhCoW91VISYFndTpF62lWDEE9YCtXYU7ACbZUjif6ccnnWc7h9Xk WPj3aLWWvYcBeW2xsv7injiKof95LSqQro+rwkYVvcIvxs6oaTfGbGOHkVGqt96mSjJb uk33D//Hz9tZzwDre9jLJx83lLBMLL/F4P8ixAXaBe69w7WmMMjoGL30h5UvH0SNXrec F2faJLJHfhi12jTEr/ji7QZrZ2i5FOGjaE+cnQ7S87/rfBkecHHPrJ31dWAixhQMzC2L dPDfOf4sxssGJi8duhsb2XNszMurKypbVB/lr56EARuawHExG5HGNc2vjTIdOGXgpUdt 2VeA== |
| X-Google-DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:cc; bh=Z8FBr+NpJ3EzSBdh9yMEUVf3c2QZ99iwkRBxlzEfoo4=; b=UEy2HtDrlJqyeEpTzPSWM3hz1LSPvFmOOjef7Taah+yPfY1NxBOQr7gr3Bs164jt2I t7iR5+iRalGz0EfD72F/ntjqnDOw31vDuv4vf6HNdmmOtfoCTwmTHREInEzJiKXrG1nu KOm9K1tVQ77yhnLV6+m7YL9AK/pon+Xgozngmdg3hBMxg4A34aHLjL/EJBZSUZl1uZ/a sJ73nGMakONfyJtqte3ZWkmYmGdZrCAlTAXW1kHZKKDh6+PDdQoxoYAOerzsl/8VTqNV YgwhHNGEmvDsXvJgDC5wQ6qwFRank+1Obvm2DE0E0kTK0pfGjzsoAxrwWZrZH+iPuIB5 3ISQ== |
| X-Gm-Message-State | AOPr4FUr9yyGrGK9DX6nuL2McxIkb49vwaQq4Jm9SDL6uRKPmmJXjaE5713Av3ANDZeSyVIv6L1OV8G5zOSk0A== |
| X-Received | by 10.107.18.232 with SMTP id 101mr1098299ios.157.1461217059038; Wed, 20 Apr 2016 22:37:39 -0700 (PDT) |
| In-Reply-To | <571843f9$0$1585$c3e8da3$5496439d@news.astraweb.com> |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.22 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| X-Mailman-Original-Message-ID | <CAPTjJmoM7hypFBXWM_PkCHmv1usUq91pst6D+uwFTgejTpPaJw@mail.gmail.com> |
| X-Mailman-Original-References | <571843f9$0$1585$c3e8da3$5496439d@news.astraweb.com> |
| Xref | csiph.com comp.lang.python:107436 |
Show key headers only | View raw
On Thu, Apr 21, 2016 at 1:07 PM, Steven D'Aprano <steve@pearwood.info> wrote: > Now I want to group subsequences. For example, I have: > > "ABCABCABCDEABCDEFABCABCABCB" > > and I want to group it into repeating subsequences. I can see two ways to > group it: > > ABC ABC ABCDE ABCDE F ABC ABC ABC B > > or: > > ABC ABC ABC D E A B C D E F ABC ABC ABC B Interesting. I've *almost* managed to (ab)use re.split for this purpose. A one-step solution can be done with re.match: >>> txt = "ABCABCABCDEABCDEFABCABCABCB" >>> re.match(r'(.+)\1+', txt) <_sre.SRE_Match object; span=(0, 9), match='ABCABCABC'> But split then returns only the grouped part: >>> re.split(r'(.+)\1+', txt) ['', 'ABC', 'DEABCDEF', 'ABC', 'B'] or *all* the grouped parts: >>> re.split(r'((.+)\2+)', txt) ['', 'ABCABCABC', 'ABC', 'DEABCDEF', 'ABCABCABC', 'ABC', 'B'] There's definitely a partial solution happening here, but I can't quite make it work. And no, I don't know if there's a standard name for it. ChrisA
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Detecting repeated subsequences of identical items Steven D'Aprano <steve@pearwood.info> - 2016-04-21 13:07 +1000
Re: Detecting repeated subsequences of identical items Ethan Furman <ethan@stoneleaf.us> - 2016-04-20 20:57 -0700
Re: Detecting repeated subsequences of identical items Ethan Furman <ethan@stoneleaf.us> - 2016-04-20 21:15 -0700
Re: Detecting repeated subsequences of identical items Chris Angelico <rosuav@gmail.com> - 2016-04-21 15:37 +1000
Re: Detecting repeated subsequences of identical items Michael Selik <michael.selik@gmail.com> - 2016-04-21 06:35 +0000
Re: Detecting repeated subsequences of identical items Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2016-04-21 18:05 +1000
Re: Detecting repeated subsequences of identical items Nobody <nobody@nowhere.invalid> - 2016-04-21 13:02 +0100
Re: Detecting repeated subsequences of identical items Michael Selik <michael.selik@gmail.com> - 2016-04-21 06:49 +0000
Re: Detecting repeated subsequences of identical items Vlastimil Brom <vlastimil.brom@gmail.com> - 2016-04-21 08:54 +0200
Re: Detecting repeated subsequences of identical items Michael Selik <michael.selik@gmail.com> - 2016-04-21 07:05 +0000
Re: Detecting repeated subsequences of identical items Alain Ketterlin <alain@universite-de-strasbourg.fr.invalid> - 2016-04-21 09:25 +0200
Re: Detecting repeated subsequences of identical items Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2016-04-21 09:53 +0100
Re: Detecting repeated subsequences of identical items Steven D'Aprano <steve@pearwood.info> - 2016-04-21 22:15 +1000
Re: Detecting repeated subsequences of identical items Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2016-04-21 15:01 +0100
Re: Detecting repeated subsequences of identical items Chris Angelico <rosuav@gmail.com> - 2016-04-22 00:12 +1000
Re: Detecting repeated subsequences of identical items Steven D'Aprano <steve@pearwood.info> - 2016-04-23 01:00 +1000
Re: Detecting repeated subsequences of identical items Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2016-04-21 15:30 +0100
Re: Detecting repeated subsequences of identical items Chris Angelico <rosuav@gmail.com> - 2016-04-22 01:02 +1000
Re: Detecting repeated subsequences of identical items Serhiy Storchaka <storchaka@gmail.com> - 2016-04-21 14:56 +0300
csiph-web