<div dir="ltr"><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Jul 3, 2013 at 7:46 PM, Oscar Benjamin <span dir="ltr"><<a href="mailto:oscar.j.benjamin@gmail.com" target="_blank">oscar.j.benjamin@gmail.com</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div id=":159" style="overflow:hidden">def partition(setx, sety):<br>
    xonly, xandy, yonly = set(), set(), set()<br>
    for set1, set2, setn in [(setx, sety, xonly), (sety, setx, yonly)]:<br>
        for val in set1:<br>
            if val in set2:<br>
                xandy.add(val)<br>
            else:<br>
                setn.add(val)<br>
    return xonly, xandy, yonly</div></blockquote></div><br><br>I don't understand why that can be more efficient that using the built-in operations:</div><div class="gmail_extra"><br></div><blockquote style="margin:0 0 0 40px;border:none;padding:0px">

<div class="gmail_extra">def partition(setx, sety):</div><div class="gmail_extra">    common = setx & sety</div><div class="gmail_extra">    return setx - common, common, sety - common</div></blockquote><div class="gmail_extra">

<br clear="all"><div>I assume that the built-in operations traverse over the set with the smallest size, and preallocate the result to that size.</div><div><br></div>-- <br><span style="color:rgb(0,102,0)">Juancarlo </span><b style="color:rgb(0,102,0)">Añez</b>
</div></div>