######## LIST PRACTICE ####### First index of element
Problem Statement
Suggest Edit
Problem Statement
The first line contains an integer N representing the size of the array.
The next line contains N space-separated integers representing the elements of the array.
The last line contains an integer 'x' whose index has to be found.
The only line of the output prints the Index or -1.
1 <= N <= 10^3
1 <= arr[i] <= 10^9
1 <= x < N
8
7 5 2 11 2 43 1 1
2
2
2 is present twice in the input array and the first time it appears is at index 2.
8
7 5 2 11 2 43 1 1
10
-1
10 is not present in the array so the output is -1.
n = int(input()) lst=(input().split()) x=input() try: print( lst.index(x) ) except ValueError : print(-1)
Comments
Post a Comment