On 2/10/07, Guido van Rossum <[EMAIL PROTECTED]> wrote: > 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.
Ah, OK. So just 'in' get the iterator for the dict values view and iterate through. Makes sense now. > (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. > Yeah, unless you want partial caching for those that are hashable, but at that point it probably isn't worth it. -Brett > --Guido > > On 2/10/07, Brett Cannon <[EMAIL PROTECTED]> wrote: > > On 2/10/07, guido.van.rossum <[email protected]> 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 > > [email protected] > > http://mail.python.org/mailman/listinfo/python-3000-checkins > > > > > -- > --Guido van Rossum (home page: http://www.python.org/~guido/) > _______________________________________________ Python-3000-checkins mailing list [email protected] http://mail.python.org/mailman/listinfo/python-3000-checkins
