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 c not in
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
Try this
t = set(bbc)
list(t
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 an indentifier will shadow the builtin str
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(C)
Traceback
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 elegant
as the one- and two-liners, but somewhat concise I guess.
def compress(s
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:
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 enumerate(str):
try:
if c != str[i
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
succinct, but a solution is currently escaping me.
def
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, 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 so far feels like it could be made clearer
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 - ABC
The code I have so far feels like it could be made clearer
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 is currently escaping me.
def compress_str(str):
new_str =
for i, c in enumerate
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 =
for i, c in enumerate(str):
try
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 at two successive
elements of a sequence:
from itertools import izip
instr
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'
import re
re.compile(r(.)\1*).sub(r\1, aaa)
'abc'
Peter
--
http://mail.python.org/mailman
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
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(aabbcc))
'abc'
import re
re.compile(r(.)\1*).sub(r\1
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
)
return new_str
Matt Porter [EMAIL PROTECTED] wrote in message
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
19 matches
Mail list logo