On Mon, Jul 11, 2011 at 8:37 PM, Xah Lee <xah...@gmail.com> wrote: > > it's funny, in all these supposedly modern high-level langs, they > don't provide even simple list manipulation functions such as union, > intersection, and the like. Not in perl, not in python, not in lisps. > (sure, lib exists, but it's a ride in the wild)
Python has them, but, as they are set functions, not list functions, they exist for the set type: Intersection: >>> set((1, 2, 3)) & set((2,3,4)) set([2, 3]) Union: >>> set((1, 2, 3)) | set((2,3,4)) set([1, 2, 3, 4]) Symmetric Difference: >>> set((1, 2, 3)) ^ set((2,3,4)) set([1, 4]) You can also get a non-symmetric difference by calling the difference method of the set: >>> set((1, 2, 3)).difference(set((2,3,4))) set([1]) >>> set((2, 3, 4)).difference(set((1,2,3))) set([4]) >>> In Python 3 (2.7?) there is even more syntactical sugar for them: {1, 2, 3} ^ {2, 3, 4} produces {1, 4}.
-- http://mail.python.org/mailman/listinfo/python-list