[Python-Dev] dict containment annoyance

tomer filiba tomerfiliba at gmail.com
Sat Aug 12 18:57:02 CEST 2006


[Aahz]
> -1
>
> This is seriously no different from an attempt to do
>
> >>> a = {}
> >>> a[ [] ] = 1

how so? i'm not trying to modify/store anything in a dict.
i'm only testing if a certain object is contained in the dict.
that's totally different.
imagine this:
>>> x = 6
>>> x < 2
am i trying to modify 'x' in any way? i'm only testing if x is
less than 2.

i fail to see your point

[David Hopwood]
> However, if it isn't hashable, asking whether it is in a dict is very
> likely to be a programming error.

not really. my program holds a blacklist of "bad objects", which
shouldn't be granted access to. instead of a list, i'm using a set
(performance, whatever). the "bad objects" are all hashable,
and i want to see if an arbitrary object is "good" or "bad", by looking
it up in the blacklist. the arbitrary object can be hashable or not,
that's not the question.

just like `"hello" != 2` returns True, instead of raising IncompatibleTypes,
i want `x in y` to return False when `x` is not contained in `y`
(with no regard to whether or not it's possible for `y` to contain `x`).

the logic is simple: every `x` is either contained in `y` or not.
if `x` *cannot* be contained in `y`, then the answer is a "strong no",
but that's still a "no".



-tomer


More information about the Python-Dev mailing list