Loading...
Loading...
Loading...
Given a list of item codes and a code x, print the position (starting from 0) of the first time x appears. If x is not in the list, print -1.
Example 1
Input
5 12 7 30 7 5 7
Output
1
7 appears at index 1 and 3. The first one counts.
Example 2
Input
3 4 5 6 9
Output
-1
Not found.
Try the problem first. Open one hint at a time.
Go through the list with enumerate so you get each index and value together.
Stop and print as soon as you find x. Only after the loop ends do you know it was missing.
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor