List Behavior when inserting new items
Diez B. Roggisch
deets at nospam.web.de
Mon Jan 29 14:05:46 EST 2007
Drew schrieb:
> I'm looking to add an element to list of items, however I'd like to
> add it at a specific index greater than the current size:
>
> list = [1,2,3]
> list.insert(10,4)
>
> What I'd like to see is something like:
>
> [1,2,3,,,,,,4]
>
> However I see:
>
> [1,2,3,4]
>
> Is there any way to produce this kind of behavior easily?
Use a dictionary?
If you know how large the list eventually will be, and that each
position is filled, you can also use range(n) to create a list.
What is your actual usecase?
diez
More information about the Python-list
mailing list