On Tue, 15 Feb 2011 10:53:56 +0100 Andrea Crotti
<andrea.crott...@gmail.com> wrote:

> Just a curiosity not a real problem, I want to pass from a string like
> 
> xxaabbddee
> to
> xx:aa:bb:dd:ee
> 
> so every two characters insert a ":".
> At the moment I have this ugly inliner
>         interleaved = ':'.join(orig[x:x+2] for x in range(0,
> len(orig), 2))
> 
> but also something like this would work
> [''.join((x,y)) for x, y in zip(orig[0::2], orig[1::2])]
> 
> any other ideas?

import re

s = 'xxaabbddee'
m = re.compile("(..)")
s1 = m.sub("\\1:", s)[:-1]

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

Reply via email to