Re: len() on mutables vs. immutables

Discussion in 'Python' started by Demian Brecht, Oct 18, 2012.

  1. 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 :)
    Demian Brecht, Oct 18, 2012
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Demian Brecht

    len() on mutables vs. immutables

    Demian Brecht, Oct 18, 2012, in forum: Python
    Replies:
    0
    Views:
    96
    Demian Brecht
    Oct 18, 2012
  2. Terry Reedy

    Re: len() on mutables vs. immutables

    Terry Reedy, Oct 18, 2012, in forum: Python
    Replies:
    0
    Views:
    108
    Terry Reedy
    Oct 18, 2012
  3. Demian Brecht

    Re: len() on mutables vs. immutables

    Demian Brecht, Oct 18, 2012, in forum: Python
    Replies:
    0
    Views:
    119
    Demian Brecht
    Oct 18, 2012
  4. Nick Cash

    RE: len() on mutables vs. immutables

    Nick Cash, Oct 18, 2012, in forum: Python
    Replies:
    0
    Views:
    87
    Nick Cash
    Oct 18, 2012
  5. Prasad, Ramit

    RE: len() on mutables vs. immutables

    Prasad, Ramit, Oct 18, 2012, in forum: Python
    Replies:
    0
    Views:
    111
    Prasad, Ramit
    Oct 18, 2012
Loading...

Share This Page