[Python-3000-checkins] r53724 - in python/branches/p3yk: Lib/test/test_dictviews.py Objects/dictobject.c

Guido van Rossum guido at python.org
Sun Feb 11 00:21:49 CET 2007


I meant the default implementation for 'in' which simply iterates over
the collection. While 'in' can be implemented efficiently using the
dict lookup for keys() and items(), for values() this doesn't work --
if you want to know if a particular value is in dict.values(), you
have to iterate over the entire dict until you find it. (I had dreams
of caching this by converting the values to a set, but was rudely
awakened when I realized that values don't need to be hashable. So
dict.values(), unlike dict.keys() and dict.items(), cannot return an
object that behaves and is as efficient as a set, without copying
anything; the only property I plan to implement (and have already done
so) is __iter__ which gives all the values in random order.

--Guido

On 2/10/07, Brett Cannon <brett at python.org> wrote:
> On 2/10/07, guido.van.rossum <python-3000-checkins at python.org> wrote:
> > Author: guido.van.rossum
> > Date: Sat Feb 10 19:55:06 2007
> > New Revision: 53724
> >
> > Modified:
> >    python/branches/p3yk/Lib/test/test_dictviews.py
> >    python/branches/p3yk/Objects/dictobject.c
> > Log:
> > Implement __contains__ for dict_keys and dict_items.
> > (Not for dict_values, where it can't be done faster than
> > the default implementation which just iterates the elements.)
>
> What default implementation?  I assume you don't mean the default way
> for dicts since you are already using that for keys and items.
>
> -Brett
> _______________________________________________
> Python-3000-checkins mailing list
> Python-3000-checkins at python.org
> http://mail.python.org/mailman/listinfo/python-3000-checkins
>


-- 
--Guido van Rossum (home page: http://www.python.org/~guido/)


More information about the Python-3000-checkins mailing list