[Python-Dev] Re: PEP 218 (sets); moving set.py to Lib

Raymond Hettinger python@rcn.com
Wed, 21 Aug 2002 23:57:10 -0400


> [Guido]
> > Um, the notation is '|' and '&', not 'or' and 'and', and those are
> > what I learned in school.  Seems pretty conventional to me (Greg
> > Wilson actually tried this out on unsuspecting newbies and found that
> > while '+' worked okay, '*' did not -- read the PEP).

[Tim]
> FYI, kjbuckets uses '+' (union) and '&' (intersection).  '*' is used for

FTI, ISETL uses '+' and '*' as synonyms for the spelled-out 'inter' and 'union' operators.

Playing with a sample session for possible inclusion in the tutorial, I've found that '|' is not nearly as clear in its intention
as '+'.


Raymond Hettinger

-------------------------------------------------------------------

from sets import Set

engineers = Set(['John', 'Jane', 'Jack', 'Janice'])
programmers = Set(['Jack', 'Sam', 'Susan', 'Janice'])
management = Set(['Jane', 'Jack', 'Susan', 'Zack'])

employees = engineers | programmers | management    # more clear with '+'
engineering_management = engineers & programmers
fulltime_management = management - engineers - programmers

engineers.add('Marvin')
print engineers, 'Look, Marvin was added'
print employees.issuperset(engineers), 'There is a problem'
print employees, 'Hmm, employees needs an update'
employees.update(engineers)
print employees, 'Looks fine now'

for group in [engineers, programmers, management, employees]:
    group.discard('Susan')
    print group