Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #64111 > unrolled thread
| Started by | Tim Chase <python.list@tim.thechases.com> |
|---|---|
| First post | 2014-01-16 16:44 -0600 |
| Last post | 2014-01-16 16:44 -0600 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: Python solve problem with string operation Tim Chase <python.list@tim.thechases.com> - 2014-01-16 16:44 -0600
| From | Tim Chase <python.list@tim.thechases.com> |
|---|---|
| Date | 2014-01-16 16:44 -0600 |
| Subject | Re: Python solve problem with string operation |
| Message-ID | <mailman.5608.1389912245.18130.python-list@python.org> |
On 2014-01-17 00:24, Nac Temha wrote:
> Hi everyone,
>
> I want to do operation with chars in the given string. Actually I
> want to grouping the same chars.
>
> For example;
>
> input : "344111133311222223377"
> operation-> (3)(44)(1111)(333)(11)(22222)(33)(77)
> output: "34131237"
>
> How can I do without list, regular expression. just using string
> operations. Using an effective methods of python for this problem.
I'm not sure what constitutes "just using string operations", but
it's quite simple with stdlib tools:
>>> from itertools import groupby
>>> ''.join(k for k,v in groupby("344111133311222223377"))
'34131237'
-tkc
Back to top | Article view | comp.lang.python
csiph-web