Right code but still test case is not running in python
<p>Given an array of ints, return True if .. 1, 2, 3, .. appears in the array somewhere.</p>

<pre><code>def array123(nums):
    for i in  nums:
       if nums[i:i+3] == [1,2,3]:
          return True
    return False
</code></pre>

<p><a href="http://codingbat.com/prob/p193604" rel="nofollow">Coding bat problem</a></p>

<p>my code is satisfying all the test cases except for nums=[1,2,3]
can someone tell me whats wrong with my code</p>

<p>You're getting wrong result because you're iterating on the value of elements not on the index of elements of elements. Try following code</p>

<pre><code>def array123(nums):
    for i in range(len(nums)-2):
       if nums[i:i+3] == [1,2,3]:
          return True
    return False
</code></pre>

<p>And remember to give the end index of list (range(len(nums)-2)) because suppose if length of your array is 4 then (range(len(nums)-2))  will be </p>

<p>(range(2)) = [0,1]</p>

<p>So the loop will iterate for 0,1 as starting index</p>

python python-3.x