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
Difference between lists and tuples in python?
What are migrations in python?
What are the features of python?
How will you capitalize the first letter of a string?
Is empty function in python?
What is pip and when it is used ?
What are the generator functions in python?
What is Python Set?
What is python good for?
Does python have long?
How do you create a list which is a reverse version on another list in python?
What are classes in python?
Is python better than matlab?
Tell me what is the difference between django, pyramid, and flask?
Why main method is static?