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

What is __init__?

3 Answers  


How to use of return keywords in python?

0 Answers  


How to install python and prepare environment?

0 Answers  


If you are ever stuck in an infinite loop, how will you break out of it?

0 Answers  


What is the purpose of "self" in python

0 Answers  


What does by python a scripting language?

0 Answers  


How do you clean pyc files?

0 Answers  


How do I run python setup py?

0 Answers  


How do I use python idle?

0 Answers  


What does range () do in python?

0 Answers  


What is file context manager?

0 Answers  


Which is faster python or java?

0 Answers  


Categories