Python solve problem with string operation
Mark Lawrence
breamoreboy at yahoo.co.uk
Thu Jan 16 17:48:50 EST 2014
On 16/01/2014 22:30, John Gordon wrote:
> In <mailman.5607.1389911083.18130.python-list at python.org> Nac Temha <naccttemha at gmail.com> writes:
>
>> --047d7b6d95d0367a3d04f01de490
>> Content-Type: text/plain; charset=ISO-8859-1
>
>> 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"
>
> input = "344111133311222223377"
> output = []
> previous_ch = None
> for ch in input:
> if ch != previous_ch:
> output.append(ch)
> previous_ch = ch
> print ''.join(output)
>
Cheat, you've used a list :)
--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.
Mark Lawrence
More information about the Python-list
mailing list