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


Groups > comp.lang.python > #31681

Re: len() on mutables vs. immutables

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!newsfeed.xs4all.nl!newsfeed5.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.029
X-Spam-Evidence '*H*': 0.94; '*S*': 0.00; 'context': 0.05; 'cpython': 0.05; 'table.': 0.07; 'dict': 0.09; 'anyway': 0.11; 'oct': 0.16; 'wrote:': 0.17; 'pointer': 0.17; 'thu,': 0.17; 'thus': 0.24; 'header:In-Reply-To:1': 0.25; 'message-id:@mail.gmail.com': 0.27; 'arithmetic': 0.29; 'hash': 0.29; 'received:209.85.215.46': 0.30; 'to:addr:python-list': 0.33; 'received:google.com': 0.34; 'pm,': 0.35; 'received:209.85': 0.35; 'keeps': 0.37; 'does': 0.37; 'why': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'to:addr:python.org': 0.39; 'header:Received:5': 0.40; 'think': 0.40; 'subject:. ': 0.66; 'grow': 0.74; 'contains.': 0.84; 'to:name:python': 0.84; '1:18': 0.91
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=WMq35P+jpmEJ2//ZyOws2pYRpxNUcVQkMcBYVjKcuic=; b=wKHsnpnmcT51HO7ajqqgAFP7klVdhXkeSLNGcoPnSj0gWKSarExr7ZlN7AWFT1CMTb BFcRne2Sm7yOdmmo69ZO/220fUJGKuEsdPGoAj4GmvLVzRx+BWquCtwzZzhvAPNI+2C/ dsfS/H6dtHuozpoA8Aq1cfjOxbZY3QIcX32OWBhqh3RUvKJdBSFylzcIO/xHZMWTlXwN +JWdvDJwRhYzd1Px1AqqSEhN+hzh1EcHJIWIHXqpcwxBce0YedqWPoKay6D7FWd1ynNn eomG77x05M319qneWXvqMbWOaHOE4ZcLPD5UqDFNLRj7o/S0uGK6h5bQ7cGXyIzhvcVu 4IpQ==
MIME-Version 1.0
In-Reply-To <5B80DD153D7D744689F57F4FB69AF4741671D06A@SCACMX008.exchad.jpmchase.net>
References <50803B2C.6010900@gmail.com> <k5phqe$2ia$1@ger.gmane.org> <5B80DD153D7D744689F57F4FB69AF4741671D06A@SCACMX008.exchad.jpmchase.net>
From Ian Kelly <ian.g.kelly@gmail.com>
Date Thu, 18 Oct 2012 13:38:33 -0600
Subject Re: len() on mutables vs. immutables
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.2471.1350589145.27098.python-list@python.org> (permalink)
Lines 9
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1350589145 news.xs4all.nl 6884 [2001:888:2000:d::a6]:37008
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:31681

Show key headers only | View raw


On Thu, Oct 18, 2012 at 1:18 PM, Prasad, Ramit
<ramit.prasad@jpmorgan.com> wrote:
> Why does pointer arithmetic work for dicts? I would think the position
> of a value would be based on the hash of the key and thus "random" for
> the context of this conversation.

It doesn't.  len() on CPython dicts is O(1) because the dict keeps
track of how many items it contains.  It needs to do this anyway so
that it can determine when to grow the internal hash table.

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


Thread

Re: len() on mutables vs. immutables Ian Kelly <ian.g.kelly@gmail.com> - 2012-10-18 13:38 -0600

csiph-web