On May 18, 1:45 pm, Gary Herron <[EMAIL PROTECTED]> wrote:
> Matt Porter wrote:
> > Hi guys,
>
> > I'm trying to compress a string.
> > E.g:
> >  "AAAABBBC" -> "ABC"
>

I'm partial to using (i)zip when I need to look at two successive
elements of a sequence:

>>> from itertools import izip
>>> instr = "aaaaaaaaaaabbbbbbbbbbdddddaaaaaaaddddddccccccc"
>>> newstr = "".join( b for a,b in izip(" "+instr,instr) if a!=b )
>>> print newstr
abdadc

-- Paul

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

Reply via email to