Compress a string

Marc Christiansen usenet at solar-empire.de
Sun May 18 15:17:43 EDT 2008


Matt Porter <mabbikeel at gmail.com> wrote:
> Hi guys,
> 
> I'm trying to compress a string.
> E.g:
>  "AAAABBBC" -> "ABC"

You mean like this?

 >>> ''.join(c for c, _ in itertools.groupby("AAAABBBCAADCASS"))
 'ABCADCAS'

HTH
  Marc



More information about the Python-list mailing list