Creating Linked Lists in Python
Roy Smith
roy at panix.com
Sat Mar 21 13:48:40 EDT 2009
In article <mailman.2379.1237642733.11746.python-list at python.org>,
Tim Chase <python.list at tim.thechases.com> wrote:
> In the past, I've done NFA with a state machine:
What I've done at times is have each state be a function. The function
returns an (output, next_state) tuple, and the main loop becomes something
like this:
state = start
for input in whatever:
output, state = state(input)
and the states look like:
def start(input):
next_state = blah
output = blah
return (output, next_state)
It's not always the right organization (and is almost certainly not for
machines with large numbers of states), but I've found it useful for a lot
of ad-hoc file parsing that I've done.
More information about the Python-list
mailing list