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: 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" To: "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> In-Reply-To: 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 Terry Reedy wrote:=0D=0A> On 10/18/2012 1:23 PM, Demian Brecht wrote:=0D=0A= > =0D=0A> > When len() is called passing an immutable built-in type (such a= s a=0D=0A> > string), I'd assume that the overhead in doing so is simply a = function=0D=0A> > call and there are no on-call calculations done=2E Is tha= t correct?=0D=0A> =0D=0A> See below=2E=0D=0A> =0D=0A> > I'd also assume tha= t mutable built-in types (such as a bytearray) would=0D=0A> > cache their s= ize internally as a side effect of mutation operations=2E Is=0D=0A> =0D=0A>= Or the length could be the difference of two pointers -- address of the=0D= =0A> first empty slot minus address of first item=2E=0D=0A> =0D=0A> > that = correct? If so, is it safe to assume that at least all built-in=0D=0A> > ty= pes observe this behavior,=0D=0A> =0D=0A> str, bytes, bytearrays, arrays, s= ets, frozensets, dicts, dictviews, and=0D=0A> ranges should all return len = in O(1) time=2E That includes the possibility=0D=0A> of a subtraction as in= dicated above=2E=0D=0A> =0D=0A=0D=0AWhy does pointer arithmetic work for di= cts? I would think the position=0D=0Aof a value would be based on the hash = of the key and thus "random" for=0D=0Athe context of this conversation=2E= =0D=0A=0D=0ARamit Prasad=0D=0A=0D=0A=0D=0AThis email is confidential and su= bject to important disclaimers and=0D=0Aconditions including on offers for = the purchase or sale of=0D=0Asecurities, accuracy and completeness of infor= mation, viruses,=0D=0Aconfidentiality, legal privilege, and legal entity di= sclaimers,=0D=0Aavailable at http://www=2Ejpmorgan=2Ecom/pages/disclosures/= email=2E