Explain how to create a multidimensional list.



Explain how to create a multidimensional list...

Answer / 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

More Python Interview Questions

How do I sort a list in python 3?

0 Answers  


What is python inheritance?

0 Answers  


How do you iterate over a list and pull element indices at the same time?

0 Answers  


What is PEP8?

0 Answers  


How many modes are there in python?

0 Answers  






Differentiate between deep and shallow copy?

0 Answers  


Mention what is flask-wtf and what are their features?

0 Answers  


What are built in types in python?

0 Answers  


What is pytest?

0 Answers  


Can we learn python in a week?

0 Answers  


What is map, filter and reduce in python?

0 Answers  


How do you disconnect from the database?

0 Answers  


Categories