simple dfa implementation with python