Python List of Lists

Share

          Python List of Lists

A list of lists is a way of creating a two-dimensional data structure in Python. In this case, each element of the main list is itself another list.

Here is a simple example of a list of lists in Python:

python
list_of_lists = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]

Here, list_of_lists is a list that contains three other lists. You can access elements in the list of lists by using two indices, where the first index is the position of the sub-list and the second index is the position of the element within that sub-list.

For example, if you want to access the number 5 from the list of lists defined above, you would do the following:

python
print(list_of_lists[1][1])

This would output:

5

This is because 5 is in the second sub-list ([4, 5, 6], where sub-list indexing starts from 0), and it’s the second element in that sub-list (again, with indexing starting from 0).

You can also modify elements in a similar way:

python
list_of_lists[1][1] = 10
print(list_of_lists)

This would output:

lua
[[1, 2, 3], [4, 10, 6], [7, 8, 9]]

In this case, we replaced the number 5 with 10 in our list of lists.

Python Training Demo Day 1

 
You can find more information about Python in this Python Link

 

Conclusion:

Unogeeks is the No.1 IT Training Institute for Python  Training. Anyone Disagree? Please drop in a comment

You can check out our other latest blogs on Python here – Python Blogs

You can check out our Best In Class Python Training Details here – Python Training

💬 Follow & Connect with us:

———————————-

For Training inquiries:

Call/Whatsapp: +91 73960 33555

Mail us at: info@unogeeks.com

Our Website ➜ https://unogeeks.com

Follow us:

Instagram: https://www.instagram.com/unogeeks

Facebook: https://www.facebook.com/UnogeeksSoftwareTrainingInstitute

Twitter: https://twitter.com/unogeeks


Share

Leave a Reply

Your email address will not be published. Required fields are marked *