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


Groups > comp.lang.python > #31680

RE: len() on mutables vs. immutables

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!news1.tnib.de!feed.news.tnib.de!news.tnib.de!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!194.109.133.85.MISMATCH!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <ramit.prasad@jpmorgan.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'cache': 0.05; 'context': 0.05; 'completeness': 0.07; 'indicated': 0.07; 'item.': 0.07; 'behavior,': 0.09; 'bytes,': 0.09; 'immutable': 0.09; 'internally': 0.09; 'minus': 0.09; 'mutable': 0.09; 'pointers': 0.09; 'received:155': 0.09; 'str,': 0.09; 'terry': 0.09; 'assume': 0.11; 'passing': 0.15; 'arrays,': 0.16; 'bytearrays,': 0.16; 'disclaimers': 0.16; 'disclaimers,': 0.16; 'from:addr:jpmorgan.com': 0.16; 'len': 0.16; 'received:155.180': 0.16; 'received:159.53': 0.16; 'received:bankone.net': 0.16; 'received:exchad.jpmchase.net': 0.16; 'received:jpmchase.com': 0.16; 'received:jpmchase.net': 0.16; 'received:svr.bankone.net': 0.16; 'reedy': 0.16; 'securities,': 0.16; 'subtraction': 0.16; 'url:disclosures': 0.16; 'url:jpmorgan': 0.16; 'wrote:': 0.17; 'pointer': 0.17; 'to:name:python-list@python.org': 0.20; 'operations.': 0.22; "i'd": 0.22; 'received:169.254': 0.24; 'thus': 0.24; 'least': 0.25; 'header:In-Reply-To:1': 0.25; 'done.': 0.27; 'possibility': 0.27; '(such': 0.27; 'accuracy': 0.27; 'arithmetic': 0.29; 'hash': 0.29; 'overhead': 0.29; 'slot': 0.29; 'received:169': 0.29; 'function': 0.30; 'could': 0.32; 'to:addr:python-list': 0.33; 'built-in': 0.35; 'so,': 0.35; 'doing': 0.35; 'pm,': 0.35; 'there': 0.35; 'should': 0.36; 'charset:us-ascii': 0.36; 'does': 0.37; 'two': 0.37; 'why': 0.37; 'subject:: ': 0.38; 'to:addr:python.org': 0.39; 'called': 0.39; 'think': 0.40; 'address': 0.60; 'first': 0.61; 'side': 0.61; 'safe': 0.63; 'information,': 0.63; 'url:email': 0.63; 'legal': 0.65; 'subject': 0.66; 'subject:. ': 0.66; 'purchase': 0.67; 'below.': 0.68; 'ranges': 0.71; 'sale': 0.76; 'calculations': 0.84; 'received:169.254.8': 0.84; 'sets,': 0.84
X-DKIM OpenDKIM Filter v2.1.3 sf3.jpmchase.com q9IJIqMt004099
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=jpmorgan.com; s=smtpout; t=1350587932; bh=Gv9vLvLJaqad5RYYCemYrIxJvMy094IQn7nyfTP8kOY=; h=From:To:Subject:Date:Message-ID:References:In-Reply-To: Content-Transfer-Encoding:MIME-Version:Content-Type; b=kq2WYqxLLlWrCcm4jrv0v+sVg8NWIYsSBH8/CMxzUAOh3Hje7MbXIj4QUjafQzf7j APl3Pe46PQOcEMqHK/mc/pBwFm9wt2p5I1FQB9lJyEXiSDtf38O4Hr4OYA+WDLDHxG /aQnQJiMHK7MKuHEz3Z5BwcXJykrT5pN2f7/Cax0=
From "Prasad, Ramit" <ramit.prasad@jpmorgan.com>
To "python-list@python.org" <python-list@python.org>
Subject RE: len() on mutables vs. immutables
Thread-Topic len() on mutables vs. immutables
Thread-Index AQHNrVVpw35MazyeyU+GZFCxCjgf6pe/pWYA///KIsA=
Date Thu, 18 Oct 2012 19:18:44 +0000
References <50803B2C.6010900@gmail.com> <k5phqe$2ia$1@ger.gmane.org>
In-Reply-To <k5phqe$2ia$1@ger.gmane.org>
Accept-Language en-US
Content-Language en-US
X-MS-Has-Attach
X-MS-TNEF-Correlator
x-originating-ip [10.67.79.47]
Content-Transfer-Encoding quoted-printable
MIME-Version 1.0
X-DLP-FWD Yes
Content-Type text/plain; charset="us-ascii"
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.2470.1350587935.27098.python-list@python.org> (permalink)
Lines 22
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1350587935 news.xs4all.nl 6914 [2001:888:2000:d::a6]:52320
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:31680

Show key headers only | View raw


Terry Reedy wrote:
> On 10/18/2012 1:23 PM, Demian Brecht wrote:
> 
> > When len() is called passing an immutable built-in type (such as a
> > string), I'd assume that the overhead in doing so is simply a function
> > call and there are no on-call calculations done. Is that correct?
> 
> See below.
> 
> > I'd also assume that mutable built-in types (such as a bytearray) would
> > cache their size internally as a side effect of mutation operations. Is
> 
> Or the length could be the difference of two pointers -- address of the
> first empty slot minus address of first item.
> 
> > that correct? If so, is it safe to assume that at least all built-in
> > types observe this behavior,
> 
> str, bytes, bytearrays, arrays, sets, frozensets, dicts, dictviews, and
> ranges should all return len in O(1) time. That includes the possibility
> of a subtraction as indicated above.
> 

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.

Ramit Prasad


This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.  

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


Thread

RE: len() on mutables vs. immutables "Prasad, Ramit" <ramit.prasad@jpmorgan.com> - 2012-10-18 19:18 +0000

csiph-web