def Array_abc(char):
for i in range(len(char) - 2):
if char[i] == 'a' and char[i + 1] == 'b' and char[i + 2] == 'c':
return True
return False
print (Array_abc(['a', 'x', 'a', 'b', 'c']))
Output
True
Explanation:
Here one can easily be confused in the second line as we have taken range(len(char)-2), in almost all questions we use -1, but here we have used -2. This can be explained because with length-2, we can use i+1 and i+2 in the loop. As we have to find a sequence for three numbers.
Code:
Output
Explanation:
Here one can easily be confused in the second line as we have taken range(len(char)-2), in almost all questions we use -1, but here we have used -2. This can be explained because with length-2, we can use i+1 and i+2 in the loop. As we have to find a sequence for three numbers.
need an explanation for this answer? contact us directly to get an explanation for this answer