<div class="gmail_quote">On Mon, Jul 11, 2011 at 8:37 PM, Xah Lee <span dir="ltr"><<a href="mailto:xahlee@gmail.com">xahlee@gmail.com</a>></span> wrote:<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
it's funny, in all these supposedly modern high-level langs, they<br>
don't provide even simple list manipulation functions such as union,<br>
intersection, and the like. Not in perl, not in python, not in lisps.<br>
(sure, lib exists, but it's a ride in the wild)</blockquote><div><br></div><div>Python has them, but, as they are set functions, not list functions, they exist for the set type:</div><div><br></div><div>Intersection:</div>
<div><div>>>> set((1, 2, 3)) & set((2,3,4))</div><div>set([2, 3])</div><div><br></div><div>Union:</div><div>>>> set((1, 2, 3)) | set((2,3,4))</div><div>set([1, 2, 3, 4])</div><div><br></div><div>Symmetric Difference:</div>
<div>>>> set((1, 2, 3)) ^ set((2,3,4))</div><div>set([1, 4])</div><div><br></div></div><div><br></div><div>You can also get a non-symmetric difference by calling the difference method of the set:</div><div><div>
>>> set((1, 2, 3)).difference(set((2,3,4)))</div>
<div>set([1])</div><div>>>> set((2, 3, 4)).difference(set((1,2,3)))</div><div>set([4])</div><div>>>></div></div><div><br></div><div>In Python 3 (2.7?) there is even more syntactical sugar for them: {1, 2, 3} ^ {2, 3, 4} produces {1, 4}.</div>
</div>