Matt Porter wrote:

> I'm trying to compress a string.
> E.g:
>   "AAAABBBC" -> "ABC"

Two more:

>>> from itertools import groupby
>>> "".join(k for k, g in groupby("aaaaaabbbbbbbbbbcccccc"))
'abc'

>>> import re
>>> re.compile(r"(.)\1*").sub(r"\1", "aaaaaaabbbbcccccccc")
'abc'

Peter
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to