Creating a list with holes

Roy Smith roy at panix.com
Fri Jan 3 10:51:47 EST 2014


In article <mailman.4853.1388763434.18130.python-list at python.org>,
 Chris Angelico <rosuav at 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.



More information about the Python-list mailing list