My code works but it is very different from the solution?
Solution 1:
You solution is poor because it only allows for a specific 3-digit sequence - i.e., 0,0,7. Imagine what you would have to do if the sequence was changed.
The provided solution is broken. For example, if the input is [0, 2, 3, 0, 7, 1] it will return True.
Here's something that actually works:
def spy_game(nums):
code = [0, 0, 7]
for i in range(len(nums)-len(code)):
if nums[i:i+len(code)] == code:
return True
return False