Compress a string
inhahe
inhahe at gmail.com
Sun May 18 17:38:17 EDT 2008
I forgot a line that says, "lc = c"
i should really test my stuff.
"inhahe" <inhahe at gmail.com> wrote in message news:...
>i see lots of neat one-liner solutions but just for the sake of argument:
>
> def compress_str(str):
> new_str = ""
> lc = ""
> for c in str:
> if c != lc: new_str.append(c)
> return new_str
>
>
> "Matt Porter" <mabbikeel at gmail.com> wrote in message
> news:mailman.1315.1211133997.12834.python-list at python.org...
>> Hi guys,
>>
>> I'm trying to compress a string.
>> E.g:
>> "AAAABBBC" -> "ABC"
>>
>> The code I have so far feels like it could be made clearer and more
>> succinct, but a solution is currently escaping me.
>>
>>
>>
>>
>> Cheers
>> Matt
>> --
>> --
>>
>
>
More information about the Python-list
mailing list