Hello,<div><br></div><div>How about this:</div><div><br></div><div>>>> str = 'xxaabbddee'</div><div>>>> ':'.join(map(''.join, zip(str[::2], str[1::2])))<br><br></div><div>In my example, it should not matter that the letters are repeating.</div>
<div><br></div><div><div class="gmail_quote">On Tue, Feb 15, 2011 at 11:53 AM, Andrea Crotti <span dir="ltr"><<a href="mailto:andrea.crotti.0@gmail.com">andrea.crotti.0@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Just a curiosity not a real problem, I want to pass from a string like<br>
<br>
xxaabbddee<br>
to<br>
xx:aa:bb:dd:ee<br>
<br>
so every two characters insert a ":".<br>
At the moment I have this ugly inliner<br>
        interleaved = ':'.join(orig[x:x+2] for x in range(0, len(orig), 2))<br>
<br>
but also something like this would work<br>
[''.join((x,y)) for x, y in zip(orig[0::2], orig[1::2])]<br>
<br>
any other ideas?<br>
<font color="#888888">--<br>
<a href="http://mail.python.org/mailman/listinfo/python-list" target="_blank">http://mail.python.org/mailman/listinfo/python-list</a><br>
</font></blockquote></div><br></div>