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


Groups > comp.lang.python > #63063

Re: Creating a list with holes

From Roy Smith <roy@panix.com>
Newsgroups comp.lang.python
Subject Re: Creating a list with holes
Date 2014-01-03 10:38 -0500
Organization PANIX Public Access Internet and UNIX, NYC
Message-ID <roy-2829D4.10383403012014@news.panix.com> (permalink)
References <mailman.4852.1388762356.18130.python-list@python.org>

Show all headers | View raw


In article <mailman.4852.1388762356.18130.python-list@python.org>,
 Larry Martell <larry.martell@gmail.com> wrote:

> I think I know the answer is no, but is there any package that allows
> creating a list with holes in it? E.g. I'd want to do something like:
> 
> x[10] = 12
> x[20] = 30

Whenever you ask, "What data structure do I want", you need to be able 
to answer, "What operations do I want to perform?, and, "What 
constraints do I have on memory use?"

Why do you want holes?  Is the issue that you're storing sparse data and 
don't want to waste memory on unused keys?  If so, a dictionary should 
do you fine.

Do you need to be able to read the values back out in a specific order?  
You can still do that with a dictionary if you're willing to re-sort the 
keys; that's O(n log n) on the number of keys, but if n is small, it 
doesn't matter.

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


Thread

Creating a list with holes Larry Martell <larry.martell@gmail.com> - 2014-01-03 10:19 -0500
  Re: Creating a list with holes eneskristo@gmail.com - 2014-01-03 07:30 -0800
    Re: Creating a list with holes Larry Martell <larry.martell@gmail.com> - 2014-01-03 10:41 -0500
      Re: Creating a list with holes Denis McMahon <denismfmcmahon@gmail.com> - 2014-01-03 18:07 +0000
        Re: Creating a list with holes Larry Martell <larry.martell@gmail.com> - 2014-01-03 19:15 -0500
          Re: Creating a list with holes Roy Smith <roy@panix.com> - 2014-01-03 20:18 -0500
            Re: Creating a list with holes Denis McMahon <denismfmcmahon@gmail.com> - 2014-01-04 02:03 +0000
  Re: Creating a list with holes Roy Smith <roy@panix.com> - 2014-01-03 10:38 -0500
    Re: Creating a list with holes Chris Angelico <rosuav@gmail.com> - 2014-01-04 02:46 +1100

csiph-web