In <mailman.5607.1389911083.18130.python-l...@python.org> Nac Temha 
<nacctte...@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)

-- 
John Gordon         Imagine what it must be like for a real medical doctor to
gor...@panix.com    watch 'House', or a real serial killer to watch 'Dexter'.

-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to