def string_matching_FSM(T, trans, m):
    """
    T: is the input sequence;
    trans: is the transition function that define the pattern P we need to look
    for;
    m: lenght of the pattern
    """
    s = 0
    for i,c in enumerate(T):
        s = trans[s][c]
        if s == m:
            return i-m+1

    return -1

    T: is the input sequence;
    trans: is the transition function that define the pattern P we need to look
    for;
    m: lenght of the pattern
    
recipes/Python/578161_String_Matching_using_Finit_State/recipe-578161.py