Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'subject:Python': 0.06; 'binary': 0.07; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:()': 0.09; 'testing,': 0.09; "wouldn't": 0.14; '"in': 0.16; 'keys)': 0.16; 'proceeds': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-ipconnect.de': 0.16; 'wrote:': 0.18; 'thu,': 0.19; 'value.': 0.19; 'header:User- Agent:1': 0.23; 'error': 0.23; 'source': 0.25; 'compare': 0.26; 'code:': 0.26; 'values': 0.27; 'header:X-Complaints-To:1': 0.27; 'testing': 0.29; 'chris': 0.29; 'membership': 0.31; '25,': 0.31; "d'aprano": 0.31; 'steven': 0.31; 'trouble': 0.34; 'list': 0.37; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'does': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; "you're": 0.61; 'save': 0.62; 'subject: & ': 0.68; 'qualified': 0.72; 'jul': 0.74; 'complexity': 0.84; '2013': 0.98 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Peter Otten <__peter__@web.de> Subject: Re: Python 3: dict & dict.keys() Date: Thu, 25 Jul 2013 10:13:47 +0200 Organization: None References: <51EF2AD8.3080105@stoneleaf.us> <51f0ce06$0$29971$c3e8da3$5496439d@news.astraweb.com> Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit X-Gmane-NNTP-Posting-Host: p5084b79f.dip0.t-ipconnect.de User-Agent: KNode/4.7.3 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 18 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1374740010 news.xs4all.nl 15963 [2001:888:2000:d::a6]:40171 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:51205 Chris Angelico wrote: > On Thu, Jul 25, 2013 at 5:04 PM, Steven D'Aprano > wrote: >> - Views support efficient (O(1) in the case of keys) membership testing, >> which neither iterkeys() nor Python2 keys() does. > > To save me the trouble and potential error of digging through the > source code: What's the complexity of membership testing on > values/items? Since you're calling it "efficient" it must be better > than O(n) which the list form would be, yet it isn't O(1) or you > wouldn't have qualified "in the case of keys". Does this mean > membership testing of the values and items views is O(log n) in some > way, eg a binary search? keys() and items() is O(1); both look up the key in the dictionary and items() then proceeds to compare the value. values() is O(n).