I asks the user to input the values of ROW to fill a 2D list. The value of column will be iterativley increase by 1.
list2D = [[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0]]
user input = [1,3,0,2] ##indexes of rows as well as values
i.e for 0th column the row = 1
1 column row = 3
2 column row = 0
3 column row = 2
so the new list will be:
newList = [[0,0,0,0],[1,0,0,0],[0,0,0,2],[0,3,0,0]]
How to do this?
insert elements in the list as user input
Page 1 of 11 Replies - 501 Views - Last Post: 30 January 2012 - 03:13 PM
Topic Sponsor:
Replies To: insert elements in the list as user input
#2
Re: insert elements in the list as user input
Posted 30 January 2012 - 03:13 PM
You can use a for loop with an extra counter.
Going by your example here's how it plays out by hand
See the patterns?
Going by your example here's how it plays out by hand
>>> list2d [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]] >>> list2d[1][0] = 1 >>> list2d[3][1] = 3 >>> list2d[0][2] = 0 >>> list2d[2][3] = 2 >>> list2d [[0, 0, 0, 0], [1, 0, 0, 0], [0, 0, 0, 2], [0, 3, 0, 0]]
See the patterns?
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote



|