intersection and union idea

fleet at teachout.org fleet at teachout.org
Tue Jul 24 11:38:06 EDT 2001


"Learning Python, First Edition (1999) page 109.  provides examples.

				- fleet -

>Message: 17
>   Date: Tue, 24 Jul 2001 08:42:27 +0100
>   From: Stephen Horne <steve at lurking.demon.co.uk>
>Subject: Re: intersection and union idea
>
>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