[Python-Dev] Re: Sets: elt in dict, lst.include

Eric S. Raymond esr@thyrsus.com
2001年1月23日 15:38:39 -0500


Ka-Ping Yee <ping@lfw.org>:
> The only change that needs to be made to support sets of immutable
> elements is to provide "in" on dictionaries. The rest is then all
> quite natural:
>> dict[key] = 1
> if key in dict: ...
> for key in dict: ...

Independently of implementation issues about sets, I think this is a
damn fine idea. +1.
> (Then we can also get rid of the ugly has_key method.)
>> For those that need mutable set elements badly enough to sacrifice
> a little speed, we can add two methods to lists:
>> lst.include(elt) # same as - if elt not in lst: lst.append(elt)
> lst.exclude(elt) # same as - while elt in lst: lst.remove(elt)

+1 on the concept, -0 on the names.
-- 
		<a href="http://www.tuxedo.org/~esr/">Eric S. Raymond</a>
[The disarming of citizens] has a double effect, it palsies the hand
and brutalizes the mind: a habitual disuse of physical forces totally
destroys the moral [force]; and men lose at once the power of
protecting themselves, and of discerning the cause of their
oppression.
 -- Joel Barlow, "Advice to the Privileged Orders", 1792-93

AltStyle によって変換されたページ (->オリジナル) /