On Tue, 15 Feb 2011 19:39:30 -0800, alex23 wrote:
> Andrea Crotti wrote:
>> At the moment I have this ugly inliner
>> interleaved = ':'.join(orig[x:x+2] for x in range(0,
>> len(orig), 2))
>
> I actually prefer this over every other solution to date.
Agreed. To me, it's the simp
Andrea Crotti wrote:
> At the moment I have this ugly inliner
> interleaved = ':'.join(orig[x:x+2] for x in range(0, len(orig), 2))
I actually prefer this over every other solution to date. If you feel
its too much behaviour in one line, I sometimes break it out into
separate values to pr
On 15/02/2011 09:53, Andrea Crotti 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))
On Feb 15, 10:09 am, Wojciech Muła
wrote:
> import re
>
> s = 'xxaabbddee'
> m = re.compile("(..)")
> s1 = m.sub("\\1:", s)[:-1]
One can modify this slightly:
s = 'xxaabbddee'
m = re.compile('..')
s1 = ':'.join(m.findall(s))
Depending on one's taste this could be clearer. The more general
answe
Hello,
How about this:
>>> str = 'xxaabbddee'
>>> ':'.join(map(''.join, zip(str[::2], str[1::2])))
In my example, it should not matter that the letters are repeating.
On Tue, Feb 15, 2011 at 11:53 AM, Andrea Crotti
wrote:
> Just a curiosity not a real problem, I want to pass from a string like
On Tue, 15 Feb 2011 10:53:56 +0100 Andrea Crotti
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] f