How are finite automata implemented in code?
问题 How does one implement a dfa or an nfa for that matter in Python code? What are some good ways to do it in python? And are they ever used in real world projects? 回答1: A straightforward way to represent a DFA is as a dictionary of dictionaries. For each state create a dictionary which is keyed by the letters of the alphabet and then a global dictionary which is keyed by the states. For example, the following DFA from the Wikipedia article on DFAs can be represented by a dictionary like this: