def contains(cat, key, container):
hash(key)<EOL>try:<EOL><INDENT>loc = cat.categories.get_loc(key)<EOL><DEDENT>except KeyError:<EOL><INDENT>return False<EOL><DEDENT>if is_scalar(loc):<EOL><INDENT>return loc in container<EOL><DEDENT>else:<EOL><INDENT>return any(loc_ in container for loc_ in loc)<EOL><DEDENT>
Helper for membership check for ``key`` in ``cat``.

This is a helper method for :method:`__contains__`
and :class:`CategoricalIndex.__contains__`.

Returns True if ``key`` is in ``cat.categories`` and the
location of ``key`` in ``categories`` is in ``container``.

Parameters
----------
cat : :class:`Categorical`or :class:`categoricalIndex`
key : a hashable object
    The key to check membership for.
container : Container (e.g. list-like or mapping)
    The container to check for membership in.

Returns
-------
is_in : bool
    True if ``key`` is in ``self.categories`` and location of
    ``key`` in ``categories`` is in ``container``, else False.

Notes
-----
This method does not check for NaN values. Do that separately
before calling this method.