Find a series in an array consisting of characters using Python
In this tutorial, we are going to learn how to find a series in an array consisting of characters using a Python program.
Here, we write a code to find a series in an array consisting of characters.
Finding a series in an array consisting of characters
Example code:
def Array_xyz(char): for i in range(len(char) - 2): if char[i] == 'x' and char[i + 1] == 'y' and char[i + 2] == 'z': return True return False print (Array_xyz(['x', 'a', 'x', 'y', 'z']))
In the above code, we used len(char)-2 but generally, we use len(char)-1. This can be explained because, with length-2, we can use i+1 and i+2 in the loop. We have to find a sequence for three numbers
Output: True
Leave a Reply