Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #64124
| Newsgroups | comp.lang.python |
|---|---|
| Subject | Re: Python solve problem with string operation |
| References | <mailman.5607.1389911083.18130.python-list@python.org> |
| From | "Rhodri James" <rhodri@wildebst.org.uk> |
| Organization | The Wildebestiary |
| Message-ID | <op.w9s3zrnr5079vu@gnudebeest> (permalink) |
| Date | 2014-01-17 01:05 +0000 |
On Thu, 16 Jan 2014 22:24:40 -0000, Nac Temha <naccttemha@gmail.com> 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 almost convinced myself this was homework, you know. A hint as to why you might want such a thing would look a lot less suspicious :-) The simplest way to do this is probably using groupby: from itertools import groupby input = "344111133311222223377" output = "".join(k for k, _ in groupby(s)) print output -- Rhodri James *-* Wildebeest Herder to the Masses
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Python solve problem with string operation Nac Temha <naccttemha@gmail.com> - 2014-01-17 00:24 +0200
Re: Python solve problem with string operation John Gordon <gordon@panix.com> - 2014-01-16 22:30 +0000
Re: Python solve problem with string operation Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-01-16 22:48 +0000
Re: Python solve problem with string operation John Gordon <gordon@panix.com> - 2014-01-16 22:58 +0000
Re: Python solve problem with string operation giacomo boffi <pecore@pascolo.net> - 2014-01-17 01:17 +0100
Re: Python solve problem with string operation giacomo boffi <pecore@pascolo.net> - 2014-01-17 01:38 +0100
Re: Python solve problem with string operation Denis McMahon <denismfmcmahon@gmail.com> - 2014-01-17 00:30 +0000
Re: Python solve problem with string operation "Rhodri James" <rhodri@wildebst.org.uk> - 2014-01-17 01:05 +0000
Re: Python solve problem with string operation Asaf Las <roegltd@gmail.com> - 2014-01-16 17:36 -0800
csiph-web