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


Groups > comp.lang.python > #63070

Re: Creating a list with holes

References <CACwCsY5P47-dB1NLQTUTQ=0aF6B+-M3y4hCxcUGmcVmHM8=-xQ@mail.gmail.com> <mailman.4853.1388763434.18130.python-list@python.org> <roy-6F59F6.10514703012014@news.panix.com>
Date 2014-01-04 02:57 +1100
Subject Re: Creating a list with holes
From Chris Angelico <rosuav@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.4859.1388764686.18130.python-list@python.org> (permalink)

Show all headers | View raw


On Sat, Jan 4, 2014 at 2:51 AM, Roy Smith <roy@panix.com> wrote:
> In article <mailman.4853.1388763434.18130.python-list@python.org>,
>  Chris Angelico <rosuav@gmail.com> wrote:
>
>> Alternatively, if you expect to fill in most of the elements, it's
>> possible you'd be happier working with a subclass of list that
>> auto-expands by filling in the spare space with a singleton meaning
>> "no element here".
>
> And, if you know ahead of time the maximum number of elements you will
> ever have:
>
> x = [None] * max_count
>
> will preallocate them all with a minimum of fuss.

Yes, as I use in the trivial example in the subsequent post. But as a
general solution this is usually insufficient. (Whether or not None is
valid as a sentinel is, of course, quite orthogonal to the discussion.
I avoided assuming that it was, the OP's now shown that it does seem
to be.)

ChrisA

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


Thread

Re: Creating a list with holes Chris Angelico <rosuav@gmail.com> - 2014-01-04 02:37 +1100
  Re: Creating a list with holes Roy Smith <roy@panix.com> - 2014-01-03 10:51 -0500
    Re: Creating a list with holes Chris Angelico <rosuav@gmail.com> - 2014-01-04 02:57 +1100

csiph-web