Computer Science - Class 12
Solutions to CBSE Sample Paper - Computer Science Class 12

Write a function INDEX_LIST(L), where L is the list of elements passed as argument to the function. The function returns another list named ‘indexList’ that stores the indices of all Non-Zero Elements of L.

For example:

If L contains [12,4,0,11,0,56]

The indexList will have - [0,1,3,5]

 

Answer:

def INDEX_LIST (L):

    indexList=[ ]

    for i in range(len(L)):

        if L[i]!= 0 :

            indexList.append(i)

    return

Slide3.JPG

Go Ad-free
Davneet Singh's photo - Co-founder, Teachoo

Made by

Davneet Singh

Davneet Singh has done his B.Tech from Indian Institute of Technology, Kanpur. He has been teaching from the past 14 years. He provides courses for Maths, Science and Computer Science at Teachoo