我正在制作一个有限状态机来迭代一些文本以进行说话者、动词和引用识别。一切都很好,但我很沮丧,我不能让我的字典按照我想要的方式工作。我想使用这样的字典,它同时具有函数指针和整数作为值:
chars = ['a','b','c']
whatever = ['cheese']
state = 0
def function():
# don't know what's going on, ask user to check
transitions = {
0: {chars: 1, whatever: 2, '“': 4},
1: {chars: 3, '“': function},
etc.
}
for item in data:
for transition in transitions[state]:
if item in transition or transition in item:
state = transitions[state][item]
但是,如果找到该代码,则此代码不会调用该函数,或者如果我让它调用该函数,则在调用 int 时会出错。
PS我不想使用图书馆等。