OPP2201-“Creating two dimensional list array”

Small example on how to create two dimensional list array in python :-

>>> n=4

>>> m=3

>>> a = [[0] * m] * n

>>> a

[[0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0]]

>>> a =[[0] * m for i in range(n)]

>>> a

[[0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0]]

>>> a=[0] * m

>>> a

[0, 0, 0]

>>> a =[[3] * m for i in range(n)]

>>> a

[[3, 3, 3], [3, 3, 3], [3, 3, 3], [3, 3, 3]]

Please click here for complete information on the same

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s