Sets in Python
Michael Hudson
mwh21 at cam.ac.uk
Tue Jan 30 13:28:37 EST 2001
"Alex Martelli" <aleaxit at yahoo.com> writes:
> "Magnus Lie Hetland" <mlh at idi.ntnu.no> wrote in message
> news:956hcd$qef$1 at tyfon.itea.ntnu.no...
> >
> > I quite often use dictionaries as sets in Python... But it doesn't really
> > seem pretty enough to me... Some arbitrariness (as with
> > "while 1: ... break" I still don't like that one...) about using what
> > to me is a value as a key, and assigning it some value -- like 1,
> > for instance... And then checking it with has_key, and removing
> > it with del...
> >
> > Isn't there a better (more beautiful) way of doing this?
>
> 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.
Cheers,
M.
--
The PROPER way to handle HTML postings is to cancel the article,
then hire a hitman to kill the poster, his wife and kids, and fuck
his dog and smash his computer into little bits. Anything more is
just extremism. -- attributed to Paul Tomblin on ASR
More information about the Python-list
mailing list