For a "sparse list" you could use a dict
instead:
mylist = {}
mylist[12] = 'a'
etc. If you want an actual list (initialize it with []
, not ()
, of course!-) you need to fill the un-set slots to _some_thing, e.g. None
, by a little auxiliary function or by subclassing list
.