Creating a list with holes
Roy Smith
roy at panix.com
Fri Jan 3 10:38:34 EST 2014
In article <mailman.4852.1388762356.18130.python-list at python.org>,
Larry Martell <larry.martell at 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.
More information about the Python-list
mailing list