Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #2330
| Date | 2011-03-31 21:20 -0500 |
|---|---|
| From | Tim Chase <python.list@tim.thechases.com> |
| Subject | Re: Extracting subsequences composed of the same character |
| References | <4d952008$0$3943$426a74cc@news.free.fr> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.62.1301624436.2990.python-list@python.org> (permalink) |
On 03/31/2011 07:43 PM, candide wrote: > "pyyythhooonnn ---> ++++" > > and you search for the subquences composed of the same character, here > you get : > > 'yyy', 'hh', 'ooo', 'nnn', '---', '++++' Or, if you want to do it with itertools instead of the "re" module: >>> s = "pyyythhooonnn ---> ++++" >>> from itertools import groupby >>> [c*length for c, length in ((k, len(list(g))) for k, g in groupby(s)) if length > 1] ['yyy', 'hh', 'ooo', 'nnn', '---', '++++'] -tkc
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Extracting subsequences composed of the same character candide <candide@free.invalid> - 2011-04-01 02:43 +0200 Re: Extracting subsequences composed of the same character MRAB <python@mrabarnett.plus.com> - 2011-04-01 02:16 +0100 Re: Extracting subsequences composed of the same character Roy Smith <roy@panix.com> - 2011-03-31 21:40 -0400 Re: Extracting subsequences composed of the same character Tim Chase <python.list@tim.thechases.com> - 2011-03-31 20:58 -0500 Re: Extracting subsequences composed of the same character Tim Chase <python.list@tim.thechases.com> - 2011-03-31 21:20 -0500 Re: Extracting subsequences composed of the same character Terry Reedy <tjreedy@udel.edu> - 2011-04-01 00:18 -0400 Re: Extracting subsequences composed of the same character candide <candide@free.invalid> - 2011-04-01 21:39 +0200
csiph-web