The time limit :1.0s Memory limit :256.0MB
Give a containing n A sequence of integers , Ask for integers a The first occurrence in a sequence is the number of .
The first line contains an integer n.
The second line contains n Nonnegative integers , For a given sequence , Each number in the sequence is not greater than 10000.
The third line contains an integer a, For the number to be found .
If a In the sequence , Output where it first appeared ( Location slave 1 Numbered starting ), Otherwise output -1.
6
1 9 4 8 3 9
9
2
n=int(input())
list = list(map(int,input().split()))
m =int(input())
try:
print(list.index(m)+1)
except:
print(-1)
map yes python Built in functions , The specified sequence will be mapped according to the provided function .
stay python3 in map To match list Use if not list
n=int(input())
list = map(int,input().split())
m =int(input())
print(list)
try:
print(list.index(m)+1)
except:
print(-1)
Output results
6
1 9 4 8 3 9
9
<map object at 0x000002543716FFA0>
-1
reason
python3 in map() return iterators type , No more python2 Medium list type . We need to use it ourselves list transformation .
iterators The type is python Iterators in .