Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #2329
| Date | 2011-03-31 20:58 -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.61.1301623137.2990.python-list@python.org> (permalink) |
On 03/31/2011 07:43 PM, candide wrote:
> Suppose you have a string, for instance
>
> "pyyythhooonnn ---> ++++"
>
> and you search for the subquences composed of the same character, here
> you get :
>
> 'yyy', 'hh', 'ooo', 'nnn', '---', '++++'
>>> import re
>>> s = "pyyythhooonnn ---> ++++"
>>> [m.group(0) for m in re.finditer(r"(.)\1+", s)]
['yyy', 'hh', 'ooo', 'nnn', '---', '++++']
>>> [(m.group(0),m.group(1)) for m in re.finditer(r"(.)\1+", s)]
[('yyy', 'y'), ('hh', 'h'), ('ooo', 'o'), ('nnn', 'n'), ('---',
'-'), ('++++', '+')]
-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