Given a pair of chars,we have to find the number of the pair in a string
Example:
string:xyxyxxxyxyxy
pair:xy
we also have to find if there is a reverse of that pair
xy->5 ans
here's the code I tried(actually the pair is fixed->xy or yx)
    try:
        for _ in range(int(input())):
            s = input()
            l=[]
            if len(s)%2==0:
                l=[(s[i:i+2]) for i in range(0, len(s), 2)]
            else:
                l=[(s[1:][i:i+2]) for i in range(0, len(s), 2)]
            if s[:-2]=='xy' or s[:-2]=='yx':
                print(l.count('xy')+l.count('yx')+1)
            else:
                print(l.count('xy') + l.count('yx'))
    except:
        pass
Any help would be appreciated
