On Sat, Jan 4, 2014 at 2:51 AM, Roy Smith <r...@panix.com> wrote:
> In article <mailman.4853.1388763434.18130.python-l...@python.org>,
>  Chris Angelico <ros...@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
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to