On Wed, Feb 10, 2010 at 1:45 AM, Peter Otten <span dir="ltr"><__<a href="mailto:peter__@web.de">peter__@web.de</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">

<div class="im">A basic implementation without regular expressions:</div>
<br>
>>> def picture(s, pic, placeholder="@"):<br>
...     parts = pic.split(placeholder)<br>
...     result = [None]*(len(parts)+len(s))<br>
...     result[::2] = parts<br>
...     result[1::2] = s<br>
...     return "".join(result)<br>
...<br>
>>><br>
>>> picture("123456789", "(@@@)-@@-(@@@)[@]")<br>
'(123)-45-(678)[9]'<br></blockquote><div><br></div><div>Huh. This is the best version of those posted, I think (especially including mine! My jumping to regex is worthy of shame, sh ame).</div><div><br></div><div>

It took a little bit to figure out what was really going on here, but its a single-pass through to do it without recursion or building a bunch of intermediate strings that are concatenated and dropped away.</div><div><br>

</div><div>Its clever, and I don't mean that in the bad way, because -all- the solutions are pretty clever in the sneaky-tricky-neat way. But this is clever-cool.</div><div><br></div><div>Just slightly dark-voodoo-incantation-esque. Slightly! </div>

<div><br></div></div><div name="mailplane_signature">--S</div>