Answer Posted / chaitanya
There are two ways in which Multidimensional list can be created:
By direct initializing the list as shown below to create multidimlist below
>>>multidimlist = [ [227, 122, 223],[222, 321, 192],[21, 122, 444]]
>>>print multidimlist[0]
>>>print multidimlist[1][2]
__________________________
Output
[227, 122, 223]
192
The second approach is to create a list of the desired length first and then fill in each element with a newly created lists demonstrated below :
>>>list=[0]*3
>>>for i in range(3):
>>> list[i]=[0]*2
>>>for i in range (3):
>>> for j in range(2):
>>> list[i][j] = i+j
>>>print list
__________________________
Output
[[0, 1], [1, 2], [2, 3]]
| Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers
What is use of list comprehension ?
What is os module?
How does for loop and while loop differ in python and when do you choose to use them?
How to python script executable on unix?
What are key words in python?
How do you sort in python?
How to install python on windows and set path variable?
How to handle deadlock in python.
Can we use else block with for loop? Answer with one example.
Will python support object oriented?
What are the differences between pass and continue?
Which operator helps to do addition operations ?
Why is this important?
Where do you use python programming? Can you describe in detail?
Number of argument’s that range() function can take ?