hi,
i've created a 2D list(ie: A=[]). i choose some of element from the list(ie: A[0][0],A[1][1],A[2][2]) and do simple add operations.
Then i created another empty 2D list to store the result. but i wanted the result to be stored at a specific index (ie: at B=[0][0],B[1][1],B[2][2]).
but i get an error."Error - list index out of range "
here is my code...can anyone spot my mistake... - A=[]
-
for i in range(3):
-
A.append([])
-
A[0]=(1,3,4,5)
-
A[1]=(2,4,6,5)
-
A[2]=(3,6,7,4)
-
-
B=[]
-
for j in range(3):
-
B.append([])
-
for i in range(3):
-
B[i][i]=2+A[i][i]
-
-
Your indentation is wrong, but I suspect it is a copy/paste problem.
You did not initialize list B properly. - A=[]
-
for i in range(3):
-
A.append([])
-
A[0]=(1,3,4,5)
-
A[1]=(2,4,6,5)
-
A[2]=(3,6,7,4)
-
-
B=[[None for i in range(4)] for j in range(3)]
-
-
for i in range(3):
-
B[i][i]=2+A[i][i]
- >>> B
-
[[3, None, None, None], [None, 6, None, None], [None, None, 9, None]]
-
>>>
2 5881 bvdet 2,851
Expert Mod 2GB
Your indentation is wrong, but I suspect it is a copy/paste problem.
You did not initialize list B properly. - A=[]
-
for i in range(3):
-
A.append([])
-
A[0]=(1,3,4,5)
-
A[1]=(2,4,6,5)
-
A[2]=(3,6,7,4)
-
-
B=[[None for i in range(4)] for j in range(3)]
-
-
for i in range(3):
-
B[i][i]=2+A[i][i]
- >>> B
-
[[3, None, None, None], [None, 6, None, None], [None, None, 9, None]]
-
>>>
Then i created another empty 2D list to store the result.
You can use an intermediate list for this as well, unless I misunderstand. - A=[]
-
A.append((1,3,4,5))
-
A.append((2,4,6,5))
-
A.append((3,6,7,4))
-
-
B=[]
-
for j in range(3):
-
temp_list = [] ## starts as empty for each "j" loop
-
for k in range(4):
-
temp_list.append(2+A[j][k])
-
-
B.append(temp_list)
Sign in to post your reply or Sign up for a free account.
Similar topics
by: simon |
last post by:
Hi,
I have two tables
Table A = {ID, Item}
Table B = {ID, IDA, subItem}
Where ID auto increment.
INSERT INTO TABLE_A ('items') values ('a')
|
by: Nikhil Patel |
last post by:
Hi all,
I am using the standard System.Windows.Forms.ComboBox controls on a form.
There are 5 or 6 comboboxes and their selection depends on each other. The
comboboxes behave strangely probably...
|
by: |
last post by:
I am stuck in a situation and I do believe that this should work, but it
doesn't.
I have a unmanaged dll, that uses MFC. This works great.
Now I recompile the unmanaged dll so it contains...
|
by: Teemu Keiski |
last post by:
Hi,
I have following type of scenario (also explained here
http://blogs.aspadvice.com/joteke/archive/2005/01/10/2196.aspx )
We have problematic web server (wink2 Standard, 1.5GB of physical...
|
by: abottchow |
last post by:
Hi all,
I'm new to the group and am seeking your advice on my Linux programming
problem.
Two programs are involved. One is myProgram.cc, which reads user's
input from keyboard and prints...
|
by: Chifo |
last post by:
hello.
i have a problem with a populate html table with data from table here
it's the problem
two querys retrieving data from table, one of querys show me a
colletion of data from 6:00 am to...
|
by: ilucks |
last post by:
I have DB(Access 97) where multi- user work in a network.
Today, I encountered this problem.
Two users were in it and do edition and adding a new data on the same
form at the same time.
User...
|
by: TD |
last post by:
I have a main form which is unbound. On this form I have two subforms
that are linked thru an unbound textbox on the main form. Both both
of the subforms are in datasheet view. This setup work...
|
by: mikeDA |
last post by:
Hello to all,
I am writing a query that is attempting to take three fields in a table, and create a new field called "MyKey." I'm doing this using concatenation. The problem: two of these fields,...
|
by: shobram |
last post by:
All problems below require some kind of input. You are free to implement
any mechanism for feeding input into your solution (for example, using hard
coded data within a unit test). You should...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
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
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |