Sets in Python

Magnus Lie Hetland mlh at idi.ntnu.no
Tue Jan 30 17:19:43 EST 2001


"Michael Hudson" <mwh21 at cam.ac.uk> wrote in message
news:m3snm07v3e.fsf at atrus.jesus.cam.ac.uk...
> "Alex Martelli" <aleaxit at yahoo.com> writes:
[...]
> > Hi Magnus!  It's been a while...
> >
> > In Python 2.1, you'll be able to use
> >     if x in dict
> > as a synonym for
> >     if dict.has_key(x)
> > [and *maybe* the for-loop equivalent, too -- I'm still unclear
> > about that one, and it doesn't seem to be in the first alpha].
>
> Uh huh; maybe not.  There have been second thoughts at high levels -
> expect a PEP and to maybe see these features in 2.2.

Does that mean "maybe not" any of the features mentioned? Or only
the ones in brackets?

And if there is to be a PEP on this, might I humbly suggest an
evaluation of some additional set-like methods etc.?
I'm not sure what all of them might be, but at least I feel
they should include adding and removing elements from the set...

For instance, you might have a method dict.add(element) which
was equivalent to dict[element] = 1 or dict[element] = None
(which is perhaps more logical) or something? dict.remove(element)
could then be equivalent to del dict[element] or something?

Or perhaps even something like dict += element for adding an
element and dict -= element for removing it? (That's what I did
in my wrapper, but I'm not sure how good it is... Since it
+ might intuitively mean union... Oh, well...)

hoping-for-prettier-sets'ly y'rs

- M

>
> Cheers,
> M.

(Oh... That looked a bit schizoid or something ;-)

--

  Magnus Lie Hetland      (magnus at hetland dot org)

 "Reality is what refuses to disappear when you stop
  believing in it"                 -- Philip K. Dick






More information about the Python-list mailing list