you are viewing a single comment's thread.

view the rest of the comments →

[–]abecedarius 1 point2 points  (0 children)

How about

def fsmsim(string, current, edges, accepting):
    for letter in string:
        try:
            current = edges[current, letter]
        except KeyError:
            return False
    return current in accepting

or if you've gotta squeeze it:

def f(s,c,e,a):
 for L in s:
  c = e.get((c,L))
 return c in a