def nfa_eclosure(M, s):
"""
>>> M = [{'':{1,2,3}}, {'b':{1}}, {'a':{2}}]
>>> nfa_eclosure(M, 0)
set([0, 1, 2, 3])
"""
try:
states = {nfa_eclosure(M, x+1) for x in xrange(len(M[s])) if M[s].get('')}
except IndexError:
states = set([])
states.add(s)
return states
Running this throws TypeError: unhashable type: 'set'
but I can't see the problem.
Edit: 2014-02-03 15:25:00
Thanks for the explanations everyone. That makes sense. Is there a "pythonic" way to take the code I have now and "splat" the contents of a set into a new set, rather than convert everything to a frozenset and then flatten it?
Edit: 2014-02-04 00:41:00
I made some modifications and now I came up with this:
try:
return set([s]).union(*(nfa_eclosure(M, x) for x in M[s].get('')))
except IndexError:
return set([s])
but I have a new error message
TypeError: union() argument after * must be a sequence, not generator
A google search didn't exactly explain the situation too well. Know what's going on?