intersection and union idea
Stephen Horne
steve at lurking.demon.co.uk
Tue Jul 24 03:42:27 EDT 2001
On Mon, 23 Jul 2001 16:57:20 -0700, "Neil Macneale"
<mac4-devnull at theory.org> wrote:
>I was day dreaming about python today, and I realized that it would be
>very python-ish to have intersection and union operators for lists and
>tuples. Eg:
>
>>>> (1,2,3,4) | (1,3,6,8)
>(1,2,3,4,6,8)
>>>> (1,2,3,4) & (1,3,6,8)
>(1,3)
You could define your own set object, or an alternative to a
dictionary or list, using a class and defining the following
methods...
__and__(self, other)
__or__(self, other)
Whether it's really useful, though, is a different thing - you're
probably better off with simple functions operation on the existing
types.
As a language addition - well, it wouldn't break anything I can see.
It could have some consiseness value, but it is really syntactic
sugar.
More information about the Python-list
mailing list