insertion in lists

Lupe luis_ at iname.com
Wed Mar 3 14:52:34 EST 2004


wes weston wrote:

> 
> 
> Lupe wrote:
>> hi,
>> 
>> I'm trying to have a kind of multi-dimensional list which seems to me to
>> be the best way to have an array of not known extension, at the begining
>> of the program.
>> 
>> if I have:
>>         element
>> 
>>         list [0]
>> and want to have list[0][0]
>>                  list[0][1]
>> 
>> how can I insert the element to that list[0][0], for example?
>> just to put things clearer, if I wanted to insert the element in list[0]
>> I could do list.insert(0,element).
>> 
>> I've tried list[0].insert(0,element) but gives me an error.
>> 
>> 
>> Luis
> 
> Luis,
>     Is this what you want?
> 
>  >>> list = []
>  >>> list.insert(0,[])
>  >>> list[0].insert(0,5)
>  >>> list
> [[5]]
> 
> wes

yes, it works for me!
Now I see why it wasn't working.
Thanks a lot!

Luis



More information about the Python-list mailing list