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
How do you sort in python 3?
Which database is best for python?
Explain what is dogpile effect? How can you prevent this effect?
Difference between lists and tuples in python?
How can I find the methods or attributes of an object?
How can you make modules in python?
What are the benefits of python?
Differentiate between split(), sub(), and subn() methods of the re module?
Explain about classes in strings?
How do you define a function in python 3?
Can we use else with for loop in python?
How will you compare two lists?
What is flask- wtf? Explain its features.
What is the use of isupper keyword in python?
Is python 0 indexed?