Matt Porter a écrit :
Hi guys,
I'm trying to compress a string.
E.g:
"BBBC" -> "ABC"
The code I have so far feels like it could be made clearer and more
succinct, but a solution is currently escaping me.
def compress_str(str):
using 'str' as
Salvatore DI DI0 a écrit :
(top-post corrected - Salvatore, please, don't top-post)
"Matt Porter" <[EMAIL PROTECTED]> a écrit dans le message de news:
[EMAIL PROTECTED]
Hi guys,
I'm trying to compress a string.
E.g:
"BBBC" -> "ABC"
> T
On Tue, 20 May 2008 00:38:57 -0400, John Salerno wrote:
> def compress(s):
> new = []
>
> for c in s:
> if c not in new:
> new.append(c)
> return ''.join(new)
>
>
> No, wait! I can do better!
>
> def compress(s):
> new = []
> [new.append(c) for c in s if
On Tue, 20 May 2008 00:09:14 -0400
John Salerno <[EMAIL PROTECTED]> wrote:
> Not that you need help anymore, but I decided to give it a try. Not as
> elegant as the one- and two-liners, but somewhat concise I guess.
Whoops! Could be cleaner! :)
def compress(s):
new = []
for c in s:
On Sun, 18 May 2008 19:06:10 +0100
"Matt Porter" <[EMAIL PROTECTED]> wrote:
> Hi guys,
>
> I'm trying to compress a string.
> E.g:
> "BBBC" -> "ABC"
Not that you need help anymore, but I decided to give it a try. Not as elegan
inhahe wrote:
> 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
Please test before posting.
>>> compress_str("
lc = ""
> for c in str:
>if c != lc: new_str.append(c)
> return new_str
>
>
> "Matt Porter" <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
>> Hi guys,
>>
>> I'm trying to compress a string.
>
ge
news:[EMAIL PROTECTED]
> Hi guys,
>
> I'm trying to compress a string.
> E.g:
> "BBBC" -> "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
> --
> --
>
--
http://mail.python.org/mailman/listinfo/python-list
On Sun, 18 May 2008 20:30:57 +0100, Peter Otten <[EMAIL PROTECTED]> wrote:
Matt Porter wrote:
I'm trying to compress a string.
E.g:
"BBBC" -> "ABC"
Two more:
from itertools import groupby
"".join(k for k, g in groupby("aa
Matt Porter <[EMAIL PROTECTED]> wrote:
> Hi guys,
>
> I'm trying to compress a string.
> E.g:
> "BBBC" -> "ABC"
You mean like this?
>>> ''.join(c for c, _ in itertools.groupby("BBBCAADCASS"))
'ABCADCAS'
HTH
Marc
--
http://mail.python.org/mailman/listinfo/python-list
Matt Porter wrote:
> I'm trying to compress a string.
> E.g:
> "BBBC" -> "ABC"
Two more:
>>> from itertools import groupby
>>> "".join(k for k, g in groupby("aabbcc"))
'abc'
>>&
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:
> > "BBBC" -> "ABC"
>
I'm partial to using (i)zip when I need to look a
Matt Porter wrote:
Hi guys,
I'm trying to compress a string.
E.g:
"BBBC" -> "ABC"
The code I have so far feels like it could be made clearer and more
succinct, but a solution is currently escaping me.
def compress_str(str):
new_str = ""
f
"Matt Porter" <[EMAIL PROTECTED]> writes:
> Hi guys,
>
> I'm trying to compress a string.
> E.g:
> "BBBC" -> "ABC"
>
> The code I have so far feels like it could be made clearer and more
> succinct, but a solution
Try this
t = set("bbc")
list(t)
Regards
Salvatore
"Matt Porter" <[EMAIL PROTECTED]> a écrit dans le message de news:
[EMAIL PROTECTED]
> Hi guys,
>
> I'm trying to compress a string.
> E.g:
> "BBBC" -&
On Sun, 18 May 2008 19:13:57 +0100, J. Clifford Dyer
<[EMAIL PROTECTED]> wrote:
On Sun, May 18, 2008 at 07:06:10PM +0100, Matt Porter wrote regarding
Compress a string:
Hi guys,
I'm trying to compress a string.
E.g:
"BBBC" -> "ABC"
The code I have
> I'm trying to compress a string.
> E.g:
>
> "BBBC" -> "ABC"
Doesn't preserve order, but insures uniqueness:
line = "BBBC"
print ''.join( set( line ) )
Malcolm
--
http://mail.python.org/mailman/listinfo/python-list
On Sun, May 18, 2008 at 07:06:10PM +0100, Matt Porter wrote regarding Compress
a string:
>
> Hi guys,
>
> I'm trying to compress a string.
> E.g:
> "BBBC" -> "ABC"
>
> The code I have so far feels like it could be made clearer and more
Hi guys,
I'm trying to compress a string.
E.g:
"BBBC" -> "ABC"
The code I have so far feels like it could be made clearer and more
succinct, but a solution is currently escaping me.
def compress_str(str):
new_str = ""
for i, c in enumera
19 matches
Mail list logo