Python Program To Find First Time Of Occurrences Index Of An Element In List

Python Program To Find First Time Of Occurrences Index Of An Element In List

Example

def firstTimeOccuringIndex(dataArray,N):
    count = 0
    for i in range(0,len(dataArray)):
        if(dataArray[i] == N):
            print("{} is First Time Occuring at Index {}.".format(N,i))
            break

data = [77,43, 65, 12, 23, 12, 36, 85, 12, 25, 12, 42]
print("Data: ",data)
n = int(input('Enter Occur Element Value: '))
firstTimeOccuringIndex(data,n)

Output:

Data:  [77, 43, 65, 12, 23, 12, 36, 85, 12, 25, 12, 42]
Enter Occur Element Value: 12
12 is First Time Occuring at Index 3.

 

Leave a comment