Explain how to create a multidimensional list.

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


Please Help Members By Posting Answers For Below Questions

Write a program to find the max value from a list without using max()?

445


Tell me what is pep 8?

463


Explain help() and dir() functions in python?

462


Which is best gui for python?

448


What are attributes in python?

442






What is for-else and while-else in python?

481


Why python is popular now?

443


Why is self used in python?

430


How do you represent binary and hexadecimal numbers?

490


Tell us something about python iterators.

484


Is python string mutable?

445


What is composition in python?

514


What is the process of compilation and loading in python?

514


What the return key word will do in python functions?

470


What is static in python?

440