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


Groups > comp.lang.python > #31673

Re: len() on mutables vs. immutables

Date 2012-10-18 11:42 -0700
From Demian Brecht <demianbrecht@gmail.com>
Subject Re: len() on mutables vs. immutables
References <50803B2C.6010900@gmail.com> <k5phqe$2ia$1@ger.gmane.org>
Newsgroups comp.lang.python
Message-ID <mailman.2462.1350585776.27098.python-list@python.org> (permalink)

Show all headers | View raw


On 10/18/2012 11:29 AM, Terry Reedy wrote:> Or the length could be the 
difference of two pointers -- address of the
 > first empty slot minus address of first item.

That would assume contiguous blocks of memory, which I would find to be 
rather dangerous (of an assumption that is) in most dynamic cases 
(obviously totally depends on implementation details).

 > 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.

Awesome. Pretty much what I figured. Of course, I'll have to dig around 
the source just to confirm this with my own eyes (more just curiosity 
than anything), so if you know whereabouts to look, it would be most 
helpful :)

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


Thread

Re: len() on mutables vs. immutables Demian Brecht <demianbrecht@gmail.com> - 2012-10-18 11:42 -0700

csiph-web