How to create a multidimensional list?

Explain how to create a multidimensional list.

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]]
How to overload constructors (or methods) in Python
How to overload constructors (or methods) in Python - _init__ () is a first method defined in a class. when an instance of a class is created, python calls __init__() to initialize the attribute of the object.........
How to send mail from a Python script
How to send mail from a Python script - The smtplib module defines an SMTP client session object that can be used to send mail to any Internet machine.......
How to generate random numbers in Python?
Thee standard module random implements a random number generator. There are also many other in this module, such as: uniform(a, b) returns a floating point number in the range [a, b]........
Post your comment