&gt; <span style="font-family: courier new,monospace;">e = &quot;&quot;.join([ s[j]+&quot;+&quot;*(i&amp;2**j&gt;0) for j in xrange(n) ])<br><br><span style="font-family: arial,helvetica,sans-serif;">Brilliant!  I was trying to do something similar, but did not have the brain bandwidth yesterday afternoon.</span><br>

<br>One simplification that I did add once I had sets available (wrote the earlier version using Python 2.3), was to replace the last few lines with:<br><br>for key in set(lhs.keys()) &amp; set(rhs.keys()):<br>    for v in lhs[key]:<br>
        for u in rhs[key]:<br>            print v + &#39; = &#39; + u<br><br><span style="font-family: arial,helvetica,sans-serif;">It may be argued that it neither makes it more readable nor more efficient - however my personal feeling is that it does express my intent better (ie. I am trying to find the set of keys that are in the intersection of the lhs and rhs).<br>
<br>Okay, now to go and get the ingredients to make Tom Yum...<br><br>Regards,</span><br style="font-family: arial,helvetica,sans-serif;"><span style="font-family: arial,helvetica,sans-serif;">Martin</span><br> <br></span><br>
<div class="gmail_quote">On Sat, Aug 22, 2009 at 12:35 PM, John La Rooy <span dir="ltr">&lt;<a href="mailto:john.larooy@gmail.com" target="_blank">john.larooy@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">

Saturday lunchtime...also using eval because we can<br><br><span style="font-family: courier new,monospace;">#!/usr/bin/env python</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">import sys</span><br style="font-family: courier new,monospace;">


<span style="font-family: courier new,monospace;">from collections import defaultdict</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">def plusses(s, filter=None):</span><br style="font-family: courier new,monospace;">


<span style="font-family: courier new,monospace;">    n=len(s)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">    res = defaultdict(list)</span><br style="font-family: courier new,monospace;">


<span style="font-family: courier new,monospace;">    for i in xrange(2**(n-1)):</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">        e = &quot;&quot;.join([ s[j]+&quot;+&quot;*(i&amp;2**j&gt;0) for j in xrange(n) ])</span><br style="font-family: courier new,monospace;">


<span style="font-family: courier new,monospace;">        t = eval(e)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">        if filter is None or t in filter:</span><br style="font-family: courier new,monospace;">


<span style="font-family: courier new,monospace;">            res[t].append(e)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">    return res</span><br style="font-family: courier new,monospace;">


<span style="font-family: courier new,monospace;">    </span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">lhs = plusses(sys.argv[1])</span><br style="font-family: courier new,monospace;">


<span style="font-family: courier new,monospace;">rhs = plusses(sys.argv[2],lhs)</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">for k in rhs.keys():</span><br style="font-family: courier new,monospace;">


<span style="font-family: courier new,monospace;">    for l in lhs[k]:</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">        for r in rhs[k]:</span><br style="font-family: courier new,monospace;">


<span style="font-family: courier new,monospace;">            print &quot;%s = %s&quot;%(l,r)</span><br><br>
<br>_______________________________________________<br>
melbourne-pug mailing list<br>
<a href="mailto:melbourne-pug@python.org" target="_blank">melbourne-pug@python.org</a><br>
<a href="http://mail.python.org/mailman/listinfo/melbourne-pug" target="_blank">http://mail.python.org/mailman/listinfo/melbourne-pug</a><br>
<br></blockquote></div><br><br clear="all"><br>-- <br>Martin Schweitzer<br>Mobile: 0412 345 938<br>E-mail: <a href="mailto:schweitzer@acm.org" target="_blank">schweitzer@acm.org</a><br>