Nested list in python by R4R Team

- Nested list is a concept of creating a list inside another list.
- List contain list is called nested list.
- Yes it is possible to create a nested list in python, as we know list is collection of different data types like int,string so we can also add list type type in the collection.

Example
[1,2,3,4] // it is a simple list.

[1,[1,2,3],2,3,4] // it is a nested list.


program-

l=[1,["one","two","three"],3,4]

#one dimensional
print(l[0])
print(l[1])
print(l[2])
print(l[3])

#two dimensional
print(l[1][0])
print(l[1][1])
print(l[1][2])


output-

1
['one', 'two', 'three']
3
4
one
two
three


-In this program, we have a list l=[1,["one","two","three"],3,4] in which ["one","two","three"] is a another list which present inside it. that's we called it nested list. and l[1] will give ["one","two","three"] then l[1][i] give items that are present inside it.




Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!