Sets in Python

Magnus Lie Hetland mlh at idi.ntnu.no
Tue Jan 30 08:56:49 EST 2001


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?

And if one was to write a small wrapper of some kind --
is there any way to implement "x in s" without a linear search?
Or does the "in" operator always loop from 0 and up?
(It would certainly be nice to be able to override it...)

--

  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