Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #51237

Re: Python 3: dict & dict.keys()

Path csiph.com!usenet.pasdenom.info!news.etla.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <ian.g.kelly@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.042
X-Spam-Evidence '*H*': 0.92; '*S*': 0.00; 'subject:Python': 0.06; 'binary': 0.07; 'subject:()': 0.09; 'testing,': 0.09; "wouldn't": 0.14; '"in': 0.16; 'dict': 0.16; 'keys)': 0.16; 'proceeds': 0.16; 'wrote:': 0.18; 'thu,': 0.19; 'value.': 0.19; '>>>': 0.22; 'error': 0.23; '2.x': 0.24; 'source': 0.25; 'compare': 0.26; 'performing': 0.26; 'code:': 0.26; 'values': 0.27; 'header:In- Reply-To:1': 0.27; 'testing': 0.29; 'chris': 0.29; 'am,': 0.29; 'message-id:@mail.gmail.com': 0.30; 'membership': 0.31; '25,': 0.31; '3.x': 0.31; "d'aprano": 0.31; 'steven': 0.31; 'copying': 0.34; 'trouble': 0.34; 'but': 0.35; 'received:google.com': 0.35; 'list': 0.37; 'step': 0.37; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'does': 0.39; 'to:addr:python.org': 0.39; "you're": 0.61; 'save': 0.62; 'more': 0.64; 'subject: & ': 0.68; 'qualified': 0.72; 'jul': 0.74; 'avoids': 0.84; 'complexity': 0.84; 'otten': 0.84; 'same,': 0.91; '2013': 0.98
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=SM0sAl2+tFYc7WKZzV81RvsL6eVmFDRBxCKrrDTnQf4=; b=1G/E/QNf+uR97fwkzhrHp6G/OJLYdRwNDraJS6cqiI0/NKMCMBFkzlYrHuj8m/OnFv sBPh3FPNNxllL0tMpwbYU7xYFCwK9XO2zaiOglDa5o/zKDZgWCcztsQgaD6Tn7x5W1q2 bnShIe1NPrBmwN17r6BldbUz35izqsZl8z6pKa4vOHDtpBD3TMuMD7YgPPSNSqnHlwuI 6G4WejKokR7MpeWK80c2u4IXI/IcBgL61J9iFhLb52eeqfthmzXod/p6kpIJCsFUktZC OcEQDZvsrTSwqcHpHDwGuyNT62oYrM8jX3phJSyu8CWyKGRRTbkEFhIC2ZFCN3bajcKB +h9A==
X-Received by 10.68.129.138 with SMTP id nw10mr16927733pbb.158.1374767653931; Thu, 25 Jul 2013 08:54:13 -0700 (PDT)
MIME-Version 1.0
In-Reply-To <ksqmmk$lq2$1@ger.gmane.org>
References <51EF2AD8.3080105@stoneleaf.us> <ksnrr9$k4t$1@ger.gmane.org> <ksp2it$21p$1@ger.gmane.org> <mailman.5061.1374692206.3114.python-list@python.org> <51f0ce06$0$29971$c3e8da3$5496439d@news.astraweb.com> <CAPTjJmoFw-tM0itPJFBqO37fPBM9UHTosCACy2Xy0Wjm2dgZmQ@mail.gmail.com> <ksqmmk$lq2$1@ger.gmane.org>
From Ian Kelly <ian.g.kelly@gmail.com>
Date Thu, 25 Jul 2013 09:53:33 -0600
Subject Re: Python 3: dict & dict.keys()
To Python <python-list@python.org>
Content-Type text/plain; charset=ISO-8859-1
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.5107.1374767657.3114.python-list@python.org> (permalink)
Lines 23
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1374767657 news.xs4all.nl 15947 [2001:888:2000:d::a6]:60268
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:51237

Show key headers only | View raw


On Thu, Jul 25, 2013 at 2:13 AM, Peter Otten <__peter__@web.de> wrote:
> Chris Angelico wrote:
>
>> On Thu, Jul 25, 2013 at 5:04 PM, Steven D'Aprano
>> <steve+comp.lang.python@pearwood.info> 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).

3.x values() is O(n) but avoids the unnecessary step of copying all the
values in the dict that you get when performing the same operation
using 2.x values().  Hence, although the asymptotic complexity is the
same, it's still more efficient.

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Re: Python 3: dict & dict.keys() Ethan Furman <ethan@stoneleaf.us> - 2013-07-24 11:31 -0700
  Re: Python 3: dict & dict.keys() alex23 <wuwei23@gmail.com> - 2013-07-25 16:01 +1000
    Re: Python 3: dict & dict.keys() Ethan Furman <ethan@stoneleaf.us> - 2013-07-25 06:47 -0700
  Re: Python 3: dict & dict.keys() Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-07-25 07:04 +0000
    Re: Python 3: dict & dict.keys() Chris Angelico <rosuav@gmail.com> - 2013-07-25 18:02 +1000
    Re: Python 3: dict & dict.keys() Peter Otten <__peter__@web.de> - 2013-07-25 10:13 +0200
    Re: Python 3: dict & dict.keys() Ian Kelly <ian.g.kelly@gmail.com> - 2013-07-25 09:53 -0600
    Re: Python 3: dict & dict.keys() Peter Otten <__peter__@web.de> - 2013-07-25 18:25 +0200

csiph-web