len() on mutables vs. immutables

Prasad, Ramit ramit.prasad at jpmorgan.com
Thu Oct 18 16:26:18 EDT 2012


Ian Kelly wrote:
> Sent: Thursday, October 18, 2012 2:39 PM
> To: Python
> Subject: Re: len() on mutables vs. immutables
> 
> On Thu, Oct 18, 2012 at 1:18 PM, Prasad, Ramit
> <ramit.prasad at 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.

That is what I was thinking "should" happen. Thanks for the 
clarification Ian.


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.  



More information about the Python-list mailing list