Why this apparent assymetry in set operations?

John Machin sjmachin at lexicon.net
Tue Jan 15 22:58:44 CET 2008


On Jan 16, 3:25 am, "Colin J. Williams" <c... at sympatico.ca> wrote:
 Colin W.
>
> I'm sorry, there appears to be a bug:

There is, but but not where you think it is :-)

> # tSet.py
> import sets

[not the bug] Earlier evidence is that you are using 2.5.1; why import
sets??

> s1= sets.Set([1, 2, 3])
> s1.union_update([3, 4,5])
> print(s1)
> s2= sets.Set([6, 7, 8])
> s1 |+ s2          # This fails:
> exceptions.TypeError: bad operand type
> for unary +: 'Set'

Try reading and understanding the exception message ... "unary +" as
in the syntactically equivalent expression
    s1 |        +s2

HTH,
John



More information about the Python-list mailing list