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 can you declare multiple assignments in one statement?

0 Answers  


What does len () do in python?

0 Answers  


Write the command to get all keys from the dictionary.

0 Answers  


What is the use of dictionary in python?

0 Answers  


Will class members accessible by instances of class?

0 Answers  


Can a set be sorted python?

0 Answers  


What is the use of sessions in Django?

2 Answers  


What is docstring? How to define it?

0 Answers  


What python frameworks do you know?

0 Answers  


What does the enum function in python do?

0 Answers  


What is the purpose of the single underscore “_” variable in python?

0 Answers  


What if you want to toggle case for a python string?

0 Answers  


Categories