473,385 Members | 1,311 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

insertion in lists

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
Jul 18 '05 #1
4 1256


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

Jul 18 '05 #2
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


Hi Luis,

Are you sure you're trying to code some python ????

To define a list named myList then :
myList=[]

To append myElement to this list :
myList.append(myElement)

That's it

Bye,

Jul 18 '05 #3
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
Jul 18 '05 #4
l=[]
l.append([])

now l=[[]] # That is this list contains a single empty list.

l.append([])

now l=[[],[]] # That is this list contains two empty lists.

l[0].append('a')

now l=[['a'],[]]

l[0].append('b')

now l=[['a','b'],[]]

l[0][0]='c'

now l=[['c'],'b'],[]]

You should be able to figure it out from here.

What is interesting is that your list can have arbitrary
elements that may be lists, strings, dictionaries, classes,
etc. and they don't have to have anything in common.

More complex example:

class x:
pass

l=['test',{'key1':1,'key2':2}, 1.5, [1,2,3,5,6,7,8], x]

Has string at l[0]
Has dictionary at l[1]
Has float at l[2]
Has another list at l[3]
Has a class reference at l[4]

WARNING-Never use 'list' as a variable name (as you did
in your example) , it is a keyword and will get redefined
by the assignment (without warning).

-Larry
"Lupe" <lu***@iname.com> wrote in message
news:c2*************@ID-202776.news.uni-berlin.de...
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

Jul 18 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Murad Nayal | last post by:
Hello, I vaguely remember reading in the manual that the order of the retrieved rows in a response to a select statement is unpredictable (unless you use an order by clause). this possibly...
3
by: Jochus | last post by:
Hi! Today we saw the information about lists. We have an assignment about CGI. That's all going well, but we're stuck at the insertion sorft of linked lists -- void voeg_in_lijst(const char*...
20
by: Patrick Guio | last post by:
Dear all, I have some problem with insertion operator together with namespace. I have a header file foo.h containing declaration of classes, typedefs and insertion operators for the typedefs in...
10
by: Anton.Nikiforov | last post by:
Dear all, i have a problem with insertion data and running post insert trigger on it. Preambula: there is a table named raw: ipsrc | cidr ipdst | cidr bytes | bigint time | timestamp...
5
by: John N. | last post by:
Hi All, Here I have a linked list each containing a char and is double linked. Then I have a pointer to an item in that list which is the current insertion point. In this funtion, the user...
3
by: Franco Perilli | last post by:
I've compiled this code and no problems, but when I run the program, it prints only the last entry i've inserted. Looks like a problem in the sorted insertion algorithm. Can u help me plz? ...
6
by: Julia | last post by:
I am trying to sort a linked list using insertion sort. I have seen a lot of ways to get around this problem but no time-efficient and space-efficient solution. This is what I have so far: ...
6
by: barcaroller | last post by:
If I insert/remove an element in a set, will an iterator to this set automatically become invalid? Does the position of the iterator before the insertion/removal matter? How are vectors and...
5
by: phiefer3 | last post by:
I'm currently a student, but this problem isn't directly related to what I have to do on an assignment. It's just a problem I've had with some supporting features. First of all, I'm using MSVS...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.