list is a data type in Python which consists of a group of elements.The elements are declared in a pair of square brackets.For example to declare a simple list you can use the following:
nums=[1,2,3,4]
you can even mix elements of different types in a list as:
listObj=[1,5,"a","b"]
The items in the list can be other lists.Instead of a string or numeric value we can declare a list as list item.This is called multidimensional list.
A multi dimensional list is declared as:
multiList=[['a','b','c'],['a','b','c']]
Accessing elements in a multidimensional list
after declaring a multi dimensional list you need to access the elements of a multi dimensional list.In the following example we are iterating all the elements of a multidimensional list
listObj=[[1,2,3],[1,2,3]] rows=len(listObj) cols=len(listObj[0]) for x in range(rows): for y in range(cols): print("item=%s"%(listObj[x][y]))


Leave a Reply