Nested list Indexing Python

Problem Statement:

We are given a list of tuples. We need to ask the user to enter a number and then we need to search for that number inside the list of tuples. At last, we need to print the index of the tuple and the index of the number that matches the number.

For example
tuplesList = [(8,2,3,7,0,7,0),(1,4,1,4,4,5),(7,4,6,57,68,9,4,3)]
Input:
Enter number: 4
Output:

Nested list Indexing Python Nested list Indexing Python We are given a list of tuples. We need to ask the user to enter a number and then we need to search for that number inside the list of tuples. At last, we need to print the index of the tuple and the index of the number that matches the number.

Code for Nested list Indexing Python:

tuplesList=[(8,2,3,7,0,7,0),(1,4,1,4,4,5),(7,4,6,57,68,9,4,3)]
n=int(input('Enter number: '))
print('Tuple index | Number Index inside tuple')
for i in range(len(tuplesList)):
    for j in range(len(tuplesList[i])):
        if tuplesList[i][j]==n:
            print('    ', i, '     |       ', j)

Output:

Output for Nested list Indexing Python

Also Read:

Share:

Author: Harry

Hello friends, thanks for visiting my website. I am a Python programmer. I, with some other members, write blogs on this website based on Python and Programming. We are still in the growing phase that's why the website design is not so good and there are many other things that need to be corrected in this website but I hope all these things will happen someday. But, till then we will not stop ourselves from uploading more amazing articles. If you want to join us or have any queries, you can mail me at admin@copyassignment.com Thank you