Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: 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; 'string.': 0.05; 'subject:Python': 0.06; 'string': 0.09; 'subject:string': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; '-tkc': 0.16; 'constitutes': 0.16; 'expression.': 0.16; 'from:addr:python.list': 0.16; 'from:addr:tim.thechases.com': 0.16; 'from:name:tim chase': 0.16; 'itertools': 0.16; 'wrote:': 0.18; 'everyone,': 0.19; '>>>': 0.22; 'input': 0.22; 'import': 0.22; 'cc:addr:python.org': 0.22; 'subject:problem': 0.24; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; 'skip:" 20': 0.27; 'header:In-Reply-To:1': 0.27; 'skip:g 30': 0.30; "i'm": 0.30; 'grouping': 0.31; 'operations.': 0.31; 'regular': 0.32; 'quite': 0.32; 'subject:with': 0.35; 'problem.': 0.35; 'but': 0.35; 'charset:us-ascii': 0.36; 'list,': 0.38; 'sure': 0.39; 'how': 0.40; 'effective': 0.61; 'simple': 0.61; 'to:addr:gmail.com': 0.65; '"just': 0.84; 'received:50.22': 0.84 Date: Thu, 16 Jan 2014 16:44:56 -0600 From: Tim Chase To: Nac Temha Subject: Re: Python solve problem with string operation In-Reply-To: References: X-Mailer: Claws Mail 3.8.1 (GTK+ 2.24.10; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - boston.accountservergroup.com X-AntiAbuse: Original Domain - python.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tim.thechases.com X-Get-Message-Sender-Via: boston.accountservergroup.com: authenticated_id: tim@thechases.com Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 25 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1389912245 news.xs4all.nl 2847 [2001:888:2000:d::a6]:52739 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:64111 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