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


Groups > comp.lang.python > #31681

Re: len() on mutables vs. immutables

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 2012-10-18 13:38 -0600
Subject Re: len() on mutables vs. immutables
Newsgroups comp.lang.python
Message-ID <mailman.2471.1350589145.27098.python-list@python.org> (permalink)

Show all headers | 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