Sets in Python

Michael Hudson mwh21 at cam.ac.uk
Tue Jan 30 18:22:10 EST 2001


"Magnus Lie Hetland" <mlh at idi.ntnu.no> writes:

> "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?

"Maybe not" on "if x in dict" (and that's my maybe - Guido's probably
decided).
"for x in dict" is not going to be in 2.1.

I think.

> 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...

Hey, if you really care, you could probably write the PEP!  I don't
know who's going to.  I'm not; I don't care much.

> 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?

Maybe.  Doubt it, personally.  *I* don't have a problem with using
what we have at the moment - it's just another idiom and once you've
seen in once, I'd expect that you'd recognize it again.

> 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...)

Again, maybe.  Somewhat less likely, I think.  The fact that you're
not sure damns it, I think.

Cheers,
M.

-- 
  If i don't understand lisp,  it would be wise to not bray about
  how lisp is stupid or otherwise criticize, because my stupidity 
  would be archived and open for all in the know to see.
                                                -- Xah, comp.lang.lisp



More information about the Python-list mailing list